Skip to content

Resolve some TODO comments in the Perseus JSON parsing code #2380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 22, 2025

Conversation

benchristel
Copy link
Member

Issue: none

Test plan:

pnpm test

Copy link
Contributor

github-actions bot commented Apr 10, 2025

Size Change: -89 B (-0.02%)

Total Size: 466 kB

Filename Size Change
packages/perseus-core/dist/es/index.js 18.5 kB -6 B (-0.03%)
packages/perseus-editor/dist/es/index.js 88.4 kB -67 B (-0.08%)
packages/perseus/dist/es/index.js 199 kB -16 B (-0.01%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 20.7 kB
packages/keypad-context/dist/es/index.js 1 kB
packages/kmath/dist/es/index.js 5.98 kB
packages/math-input/dist/es/index.js 98.6 kB
packages/math-input/dist/es/strings.js 1.61 kB
packages/perseus-linter/dist/es/index.js 7.05 kB
packages/perseus-score/dist/es/index.js 9.04 kB
packages/perseus-utils/dist/es/index.js 403 B
packages/perseus/dist/es/strings.js 7.49 kB
packages/pure-markdown/dist/es/index.js 1.22 kB
packages/simple-markdown/dist/es/index.js 6.71 kB

compressed-size-action

Copy link
Contributor

github-actions bot commented Apr 10, 2025

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (5482421) and published it to npm. You
can install it using the tag PR2380.

Example:

pnpm add @khanacademy/perseus@PR2380

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.js -t PR2380

Copy link
Collaborator

@jeremywiebe jeremywiebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really happy to see how the parsers are letting us improve things. Thanks for that!

I noticed a few linter violations at the bottom of the file listing. Not sure if they're valid...

image

@@ -32,7 +32,5 @@ export const parseMeasurerWidget: Parser<MeasurerWidget> = parseWidget(
rulerPixels: number,
rulerLength: number,
box: pair(number, number),
// TODO(benchristel): static is not used. Remove it?
static: defaulted(boolean, () => false),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! My guess is that this snuck into the object data at some point by accident.

@@ -163,7 +163,7 @@ type RenderProps = {
* Shapes (points, chords, etc) displayed on the graph that cannot be moved
* by the user.
*/
lockedFigures?: ReadonlyArray<LockedFigure>;
lockedFigures: ReadonlyArray<LockedFigure>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love that these parsers are giving us the ability to make the production code safer/cleaner!

Copy link
Contributor

@handeyeco handeyeco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

@@ -1192,9 +1192,6 @@ export type PerseusMeasurerWidgetOptions = {
rulerLength: number;
// Containing area [width, height]
box: [number, number];
// TODO(benchristel): static is not used. Remove it?
// Always false. Not used for this widget
static: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, static is so annoying

Copy link
Contributor

@Myranae Myranae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to remind you to add back coords in interactive graph and to point out some checks need to be fixed. Also, since data-schema changed, we might need to inform CP, iirc? Just one NB question, but looks good otherwise :)

Comment on lines -337 to +331
{props.lockedFigures && (
<GraphLockedLabelsLayer
lockedFigures={props.lockedFigures}
/>
)}
<GraphLockedLabelsLayer
lockedFigures={props.lockedFigures}
/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So before when lockedFigures was optional, if it was falsy in some way, then this GraphLockedLabelsLayer element wouldn't be included. Now it's always included. Could that cause any side effects with interaction or the UI?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this would render in the DOM if lockedFigures length is 0, because the outermost layer in packages/perseus/src/widgets/interactive-graphs/graph-locked-labels-layer.tsx is a React fragment. It only renders the actual labels themselves if there are any.

So I think this is fine.

@benchristel benchristel changed the base branch from benc/radio-parser-types to main April 14, 2025 22:16
Copy link
Contributor

@nishasy nishasy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Looks good to me.

I added one question for my own understanding, but I don't anticipate it being a problem.

Comment on lines -337 to +331
{props.lockedFigures && (
<GraphLockedLabelsLayer
lockedFigures={props.lockedFigures}
/>
)}
<GraphLockedLabelsLayer
lockedFigures={props.lockedFigures}
/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this would render in the DOM if lockedFigures length is 0, because the outermost layer in packages/perseus/src/widgets/interactive-graphs/graph-locked-labels-layer.tsx is a React fragment. It only renders the actual labels themselves if there are any.

So I think this is fine.

@@ -782,7 +782,7 @@ export type PerseusInteractiveGraphWidgetOptions = {
correct: PerseusGraphType;
// Shapes (points, chords, etc) displayed on the graph that cannot
// be moved by the user.
lockedFigures?: ReadonlyArray<LockedFigure>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very exciting! The rest of the code for making lockedFigures required makes sense to me. Same for labels.

Only one question for my own understanding: Is there any possibility of this causing issues for old exercise items that saved this as null or undefined? Or would that be fixed by the parser?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will be fixed up by the parser! It will default null and undefined to an empty array.

@benchristel benchristel changed the base branch from main to benc/idempotent-defaulted April 17, 2025 22:26
@benchristel benchristel force-pushed the benc/idempotent-defaulted branch from bcb6197 to d36f830 Compare April 22, 2025 18:31
Base automatically changed from benc/idempotent-defaulted to main April 22, 2025 18:48
@benchristel benchristel merged commit 1f88cc1 into main Apr 22, 2025
8 checks passed
@benchristel benchristel deleted the benc/parser-todos branch April 22, 2025 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants