Fix Graphie toFront crash from undefined elements in test data#3844
Conversation
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (0fb7231) and published it to npm. You Example: pnpm add @khanacademy/perseus@PR3844If you are working in Khan Academy's frontend, you can run the below command. ./dev/tools/bump_perseus_version.ts -t PR3844If you are working in Khan Academy's webapp, you can run the below command. ./dev/tools/bump_perseus_version.js -t PR3844 |
|
Size Change: +2 B (0%) Total Size: 517 kB 📦 View Changed
ℹ️ View Unchanged
|
| // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2. | ||
| nestedMap(this._elements, (elem) => { | ||
| if (_.isFunction(elem.toFront)) { | ||
| if (elem && _.isFunction(elem.toFront)) { |
There was a problem hiding this comment.
This follows the pattern we see above in remove() where it guards against "falsey" elements being in this._elements.
b7fe5c1 to
f29deca
Compare
| isTickCtrl: false, | ||
| isInequality: false, | ||
| divisionRange: [1, 12], | ||
| numDivisions: 5, |
There was a problem hiding this comment.
Our data-schema.ts doesn't properly model the requirements of the number-line. We require tickStep or numDivisions, but we don't support both being omitted.
| initialX: 2, | ||
| correctX: 2, | ||
| labelRange: [-5, 5], | ||
| labelStyle: "integer", |
There was a problem hiding this comment.
This is not even a supported labelStyle. See #3843
3f01156 to
a3716a4
Compare
…ements in test data
…mers when a labelStyle is used that is invalid (causing an 'undefined' entity to be added to Graphi'es tracking list of entities - resulting in a call to `.toFront()` on this `undefined` entity).
aed7728 to
7b80fe6
Compare
|
/snapshot |
1 similar comment
|
/snapshot |
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @khanacademy/perseus@80.0.0 ### Major Changes - [#3843](#3843) [`47f9f11`](47f9f11) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - [number-line] Narrow `labelStyle` type to the supported list of styles: "decimal", "improper", "mixed", and "non-reduced". Also removes legacy code for long-removed label style `"decimal ticks"`. ### Patch Changes - [#3849](#3849) [`45fbde7`](45fbde7) Thanks [@nishasy](https://github.com/nishasy)! - [ColorSync][Plotter] Add Plotter visual regression stories - [#3753](#3753) [`cbd7ea7`](cbd7ea7) Thanks [@catandthemachines](https://github.com/catandthemachines)! - Re-organize interactive graph string files to centralize string patterns and streamline testing. - [#3844](#3844) [`86593cf`](86593cf) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix crash in Graphie consumers when a labelStyle is used that is invalid (causing an 'undefined' entity to be added to Graphi'es tracking list of entities - resulting in a call to `.toFront()` on this `undefined` entity). - [#3856](#3856) [`387df6c`](387df6c) Thanks [@nishasy](https://github.com/nishasy)! - [ColorSync][Interactive Graph] Use semantic tokens in the Interactive Graph widget - [#3870](#3870) [`15bdd71`](15bdd71) Thanks [@ivyolamit](https://github.com/ivyolamit)! - Fix thin border around the interactive graph - [#3771](#3771) [`024ef46`](024ef46) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Fix table (and block math) text not scaling with the device font scale on mobile: Zoomable now fits content to the zoom-adjusted container width instead of cancelling out the CSS zoom applied for font enlargement - Updated dependencies \[[`b5f7a73`](b5f7a73), [`47f9f11`](47f9f11)]: - @khanacademy/perseus-core@31.0.0 - @khanacademy/math-input@26.6.0 - @khanacademy/keypad-context@3.2.73 - @khanacademy/kmath@2.4.32 - @khanacademy/perseus-linter@5.1.13 - @khanacademy/perseus-score@8.12.5 ## @khanacademy/perseus-core@31.0.0 ### Major Changes - [#3843](#3843) [`47f9f11`](47f9f11) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - [number-line] Narrow `labelStyle` type to the supported list of styles: "decimal", "improper", "mixed", and "non-reduced". Also removes legacy code for long-removed label style `"decimal ticks"`. ### Minor Changes - [#3862](#3862) [`b5f7a73`](b5f7a73) Thanks [@handeyeco](https://github.com/handeyeco)! - Add support for subscript in the MathInput keypad ## @khanacademy/math-input@26.6.0 ### Minor Changes - [#3862](#3862) [`b5f7a73`](b5f7a73) Thanks [@handeyeco](https://github.com/handeyeco)! - Add support for subscript in the MathInput keypad ### Patch Changes - Updated dependencies \[[`b5f7a73`](b5f7a73), [`47f9f11`](47f9f11)]: - @khanacademy/perseus-core@31.0.0 - @khanacademy/keypad-context@3.2.73 ## @khanacademy/keypad-context@3.2.73 ### Patch Changes - Updated dependencies \[[`b5f7a73`](b5f7a73), [`47f9f11`](47f9f11)]: - @khanacademy/perseus-core@31.0.0 ## @khanacademy/kmath@2.4.32 ### Patch Changes - Updated dependencies \[[`b5f7a73`](b5f7a73), [`47f9f11`](47f9f11)]: - @khanacademy/perseus-core@31.0.0 ## @khanacademy/perseus-editor@34.2.1 ### Patch Changes - [#3870](#3870) [`15bdd71`](15bdd71) Thanks [@ivyolamit](https://github.com/ivyolamit)! - Fix thin border around the interactive graph - [#3827](#3827) [`4ca460f`](4ca460f) Thanks [@anakaren-rojas](https://github.com/anakaren-rojas)! - Moves issues panel out of item editor into editor - Updated dependencies \[[`45fbde7`](45fbde7), [`b5f7a73`](b5f7a73), [`cbd7ea7`](cbd7ea7), [`86593cf`](86593cf), [`387df6c`](387df6c), [`15bdd71`](15bdd71), [`47f9f11`](47f9f11), [`024ef46`](024ef46)]: - @khanacademy/perseus@80.0.0 - @khanacademy/perseus-core@31.0.0 - @khanacademy/math-input@26.6.0 - @khanacademy/keypad-context@3.2.73 - @khanacademy/kmath@2.4.32 - @khanacademy/perseus-linter@5.1.13 ## @khanacademy/perseus-linter@5.1.13 ### Patch Changes - Updated dependencies \[[`b5f7a73`](b5f7a73), [`47f9f11`](47f9f11)]: - @khanacademy/perseus-core@31.0.0 - @khanacademy/kmath@2.4.32 ## @khanacademy/perseus-score@8.12.5 ### Patch Changes - Updated dependencies \[[`b5f7a73`](b5f7a73), [`47f9f11`](47f9f11)]: - @khanacademy/perseus-core@31.0.0 - @khanacademy/kmath@2.4.32 Author: khan-actions-bot Reviewers: jeremywiebe Required Reviewers: Approved By: jeremywiebe Checks: ✅ 11 checks were successful Pull Request URL: #3871
Summary:
createSimpleClassingraphie-classes.tshas atoFront()method that iterates overthis._elementsand callselem.toFront()on each one. The null check only guarded againstelem.toFrontnot being a function, but didn't guard againstelemitself beingundefined— causing a crash when the elements array contained a sparse entry.The root cause was test data in
all-widgets.testdata.tsusinglabelStyle: "integer", which is not a valid value. The number line's_label()function returnsundefinedfor unrecognised styles, pushingundefinedinto the elements array and triggering the crash whentoFront()was called. This PR fixes the null guard ingraphie-classes.tsto be defensive against undefined elements, and corrects the test data to uselabelStyle: "decimal"with a validnumDivisions.And the fixed rendering:
Issue: none
Test plan:
pnpm testeditors/EditorPagestory with editing disabled — confirm the number line widget renders without crashing