Skip to content
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

fix: invalidate node maps when nodes change in-between paints #5694. #5746

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DustinMackintosh
Copy link

Description
This fixes an editor crash where the user types quickly after earlier nodes have been added, split or deleted, but the node maps have not yet been regenerated on React render.

Issue
Fixes: (link to issue)

Example
Recording (from issue linked above)
https://github.com/user-attachments/assets/a68453b1-df47-4324-a542-9313569958ca

Sandbox (from issue linked above)
https://codesandbox.io/s/slate-selection-change-repro-ztssmp

Context
The NODE_TO_INDEX WeakMap is built on each React render as part of the useChildren hook. Both onDOMBeforeInput and onDOMSelectionChange use these maps to set the selection. This change introduces a new WeakMap called IS_NODE_MAP_DIRTY to track whether the underlying nodes have changed (eg: remove_node or insert_node), allowing those methods to skip attempts to setSelection that could crash the component.

Recommend you compare with "Ignore white space" selected.

Checks

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn fix.)
  • The relevant examples still work. (Run examples with yarn start.)
  • [NA] You've added a changeset if changing functionality. (Add one with yarn changeset add.)

Copy link

changeset-bot bot commented Oct 18, 2024

⚠️ No Changeset found

Latest commit: 5185aba

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

onDOMSelectionChange causes crash during concurrent updates
1 participant