[Image] | (CX) | Handle null width/height in image editor#3583
Conversation
…e editor There was a crash that happened due to a divide by zero error when the width or height was zero. Adding a check for that. I also disabled the scale fields for images with invalid size, along with a warning encouraging pressing the recalculate button. Issue: https://khanacademy.atlassian.net/browse/LEMS-4080 Test plan: `pnpm jest packages/perseus-editor/src/widgets/image-editor/components/image-scale-input.tsx` Storybook - `/?path=/story/widgets-image-editor-demo--image-with-empty-size-with-scale-flag`
…th/height in image editor
🗄️ Schema Change: No Changes ✅ |
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (d21c899) and published it to npm. You Example: pnpm add @khanacademy/perseus@PR3583If you are working in Khan Academy's frontend, you can run the below command. ./dev/tools/bump_perseus_version.ts -t PR3583If you are working in Khan Academy's webapp, you can run the below command. ./dev/tools/bump_perseus_version.js -t PR3583 |
🛠️ Item Splitting: No Changes ✅ |
|
Size Change: +119 B (+0.02%) Total Size: 504 kB 📦 View Changed
ℹ️ View Unchanged
|
There was a problem hiding this comment.
LGTM! I left one question inline.
EDIT: okay, my inline comment apparently didn't post, because "An internal error occurred, please try again.." I was wondering if we should also validate that width and height are positive and real, i.e. not NaN or Infinity.
If you're able to add this @nishasy , I think it's worth while to future proof it. |
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@77.5.0 ### Minor Changes - [#3597](#3597) [`a51b5358a0`](a51b535) Thanks [@handeyeco](https://github.com/handeyeco)! - Deprecate excludeDenylistKeys and add workaround for `graded` ### Patch Changes - [#3593](#3593) [`7dd1ff6114`](7dd1ff6) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Fix blue line on vector when graph becomes interactive after correct answer - [#3546](#3546) [`651efcc50b`](651efcc) Thanks [@nishasy](https://github.com/nishasy)! - Add new lint rule to avoid using `as` and suppress lint errors for existing instances of `as` - [#3584](#3584) [`e5e24fb670`](e5e24fb) Thanks [@catandthemachines](https://github.com/catandthemachines)! - Improving screen reader experience for pause/play button on image gifs. - Updated dependencies \[[`651efcc50b`](651efcc), [`51dd982ad9`](51dd982)]: - @khanacademy/kas@2.2.3 - @khanacademy/math-input@26.4.20 - @khanacademy/perseus-core@26.0.3 - @khanacademy/perseus-linter@5.0.3 - @khanacademy/perseus-score@8.8.2 - @khanacademy/pure-markdown@2.2.8 - @khanacademy/simple-markdown@2.2.3 - @khanacademy/keypad-context@3.2.48 - @khanacademy/kmath@2.4.6 ## @khanacademy/kas@2.2.3 ### Patch Changes - [#3546](#3546) [`651efcc50b`](651efcc) Thanks [@nishasy](https://github.com/nishasy)! - Add new lint rule to avoid using `as` and suppress lint errors for existing instances of `as` ## @khanacademy/keypad-context@3.2.48 ### Patch Changes - Updated dependencies \[[`651efcc50b`](651efcc), [`51dd982ad9`](51dd982)]: - @khanacademy/perseus-core@26.0.3 ## @khanacademy/kmath@2.4.6 ### Patch Changes - Updated dependencies \[[`651efcc50b`](651efcc), [`51dd982ad9`](51dd982)]: - @khanacademy/perseus-core@26.0.3 ## @khanacademy/math-input@26.4.20 ### Patch Changes - [#3546](#3546) [`651efcc50b`](651efcc) Thanks [@nishasy](https://github.com/nishasy)! - Add new lint rule to avoid using `as` and suppress lint errors for existing instances of `as` - Updated dependencies \[[`651efcc50b`](651efcc), [`51dd982ad9`](51dd982)]: - @khanacademy/perseus-core@26.0.3 - @khanacademy/keypad-context@3.2.48 ## @khanacademy/perseus-core@26.0.3 ### Patch Changes - [#3546](#3546) [`651efcc50b`](651efcc) Thanks [@nishasy](https://github.com/nishasy)! - Add new lint rule to avoid using `as` and suppress lint errors for existing instances of `as` - [#3570](#3570) [`51dd982ad9`](51dd982) Thanks [@benchristel](https://github.com/benchristel)! - The Perseus parsers now guard against NaN and Infinity values in number fields. These values get converted to null by `JSON.stringify`, and previously caused the parsers to be non-idempotent. - Updated dependencies \[[`651efcc50b`](651efcc)]: - @khanacademy/kas@2.2.3 - @khanacademy/pure-markdown@2.2.8 ## @khanacademy/perseus-editor@31.2.2 ### Patch Changes - [#3546](#3546) [`651efcc50b`](651efcc) Thanks [@nishasy](https://github.com/nishasy)! - Add new lint rule to avoid using `as` and suppress lint errors for existing instances of `as` - [#3583](#3583) [`e6e297c793`](e6e297c) Thanks [@nishasy](https://github.com/nishasy)! - [Image] | (CX) | Handle null width/height in image editor - [#3597](#3597) [`a51b5358a0`](a51b535) Thanks [@handeyeco](https://github.com/handeyeco)! - Deprecate excludeDenylistKeys and add workaround for `graded` - Updated dependencies \[[`7dd1ff6114`](7dd1ff6), [`651efcc50b`](651efcc), [`e5e24fb670`](e5e24fb), [`a51b5358a0`](a51b535), [`51dd982ad9`](51dd982)]: - @khanacademy/perseus@77.5.0 - @khanacademy/kas@2.2.3 - @khanacademy/math-input@26.4.20 - @khanacademy/perseus-core@26.0.3 - @khanacademy/perseus-linter@5.0.3 - @khanacademy/perseus-score@8.8.2 - @khanacademy/keypad-context@3.2.48 - @khanacademy/kmath@2.4.6 ## @khanacademy/perseus-linter@5.0.3 ### Patch Changes - [#3546](#3546) [`651efcc50b`](651efcc) Thanks [@nishasy](https://github.com/nishasy)! - Add new lint rule to avoid using `as` and suppress lint errors for existing instances of `as` - Updated dependencies \[[`651efcc50b`](651efcc), [`51dd982ad9`](51dd982)]: - @khanacademy/kas@2.2.3 - @khanacademy/perseus-core@26.0.3 - @khanacademy/pure-markdown@2.2.8 - @khanacademy/kmath@2.4.6 ## @khanacademy/perseus-score@8.8.2 ### Patch Changes - [#3546](#3546) [`651efcc50b`](651efcc) Thanks [@nishasy](https://github.com/nishasy)! - Add new lint rule to avoid using `as` and suppress lint errors for existing instances of `as` - Updated dependencies \[[`651efcc50b`](651efcc), [`51dd982ad9`](51dd982)]: - @khanacademy/kas@2.2.3 - @khanacademy/perseus-core@26.0.3 - @khanacademy/kmath@2.4.6 ## @khanacademy/pure-markdown@2.2.8 ### Patch Changes - [#3546](#3546) [`651efcc50b`](651efcc) Thanks [@nishasy](https://github.com/nishasy)! - Add new lint rule to avoid using `as` and suppress lint errors for existing instances of `as` - Updated dependencies \[[`651efcc50b`](651efcc)]: - @khanacademy/simple-markdown@2.2.3 ## @khanacademy/simple-markdown@2.2.3 ### Patch Changes - [#3546](#3546) [`651efcc50b`](651efcc) Thanks [@nishasy](https://github.com/nishasy)! - Add new lint rule to avoid using `as` and suppress lint errors for existing instances of `as` Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Summary:
There was a crash that happened due to a divide by zero error when the
width or height was zero.
Adding a check for that.
I also disabled the scale fields for images with invalid size, along
with a warning encouraging pressing the recalculate button.
Issue: https://khanacademy.atlassian.net/browse/LEMS-4080
Test plan:
pnpm jest packages/perseus-editor/src/widgets/image-editor/components/image-scale-input.tsxStorybook
/?path=/story/widgets-image-editor-demo--image-with-empty-size-with-scale-flagScreenshots & demo
Screen.Recording.2026-05-05.at.6.40.30.PM.mov