Skip to content

Conversation

@SonicScrewdriver
Copy link
Contributor

@SonicScrewdriver SonicScrewdriver commented Oct 23, 2025

This PR fixes the long-standing cursor jumping issue in Article and Exercise editors by moving the debouncing from the Perseus Editors to the upstream editors.

Issue

Issue: LEMS-3152
When users type quickly, the cursor jumps to the end of text fields. This happens because the frontend immediately updates state and passes content back to Perseus as props, creating a circular update cycle that loses cursor position.

Solution

Moved the debounce/timeout from Perseus to the Frontend's handling of Perseus onChange events, which should break the circular update cycle and prevent the cursor from jumping forward unexpectedly when typing quickly.

Future Work

A more comprehensive solution could add dedicated APIs (insertImage(), setContent()) for content updates, ideally eliminating the need for prop-state synchronization at all.

Suggested update for anyone using Perseus Editors ⚠️

External Perseus consumers will likely need to debounce/throttle their onChange handlers to avoid performance issues and cursor jumping. Previously Perseus handled this internally with a 200ms delay (apiOptions.editorChangeDelay), but my testing has indicated that a 50ms delay is sufficient on the Perseus consumer side. However, we don't believe there are currently any external consumers of the Perseus Editors - so the impact is possibly negligible. I will make sure to notify any partners, but we should be safe to go!

Test plan:

  • All tests pass
  • Manual testing across multiple devices (Chromebook, Media PC, Dev Laptop)
  • No perceptible lag increase compared to production and cursor issue appears resolved.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 23, 2025

🗄️ Schema Change: No Changes ✅

@github-actions
Copy link
Contributor

github-actions bot commented Oct 23, 2025

Size Change: -46 B (-0.01%)

Total Size: 497 kB

Filename Size Change
packages/perseus-editor/dist/es/index.js 96.6 kB -46 B (-0.05%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 20.8 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 99.2 kB
packages/math-input/dist/es/strings.js 1.61 kB
packages/perseus-core/dist/es/index.item-splitting.js 13.1 kB
packages/perseus-core/dist/es/index.js 22.4 kB
packages/perseus-linter/dist/es/index.js 7.21 kB
packages/perseus-score/dist/es/index.js 9.2 kB
packages/perseus-utils/dist/es/index.js 403 B
packages/perseus/dist/es/index.js 204 kB
packages/perseus/dist/es/strings.js 7.71 kB
packages/pure-markdown/dist/es/index.js 1.39 kB
packages/simple-markdown/dist/es/index.js 6.71 kB

compressed-size-action

@github-actions
Copy link
Contributor

github-actions bot commented Oct 23, 2025

🛠️ Item Splitting: No Changes ✅

@github-actions
Copy link
Contributor

github-actions bot commented Oct 23, 2025

npm Snapshot: Published

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

Example:

pnpm add @khanacademy/perseus@PR2976

If you are working in Khan Academy's frontend, you can run the below command.

./dev/tools/bump_perseus_version.ts -t PR2976

If you are working in Khan Academy's webapp, you can run the below command.

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

@github-actions github-actions bot added schema-change Attached to PRs when we detect Perseus Schema changes in it and removed schema-change Attached to PRs when we detect Perseus Schema changes in it labels Oct 27, 2025
@SonicScrewdriver SonicScrewdriver changed the title docs(changeset): Moving debouncing to frontend (better changeset later after testing) Resolving the cursor jumping in the Editor bug Oct 29, 2025
@SonicScrewdriver SonicScrewdriver marked this pull request as ready for review October 29, 2025 18:29
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.

2 participants