WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@DustinMackintosh
Copy link
Contributor

@DustinMackintosh DustinMackintosh commented Oct 18, 2024

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.)
  • You've added a changeset if changing functionality. (Add one with yarn changeset add.)

@changeset-bot
Copy link

changeset-bot bot commented Oct 18, 2024

🦋 Changeset detected

Latest commit: dcebdba

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
slate-react Patch

Not sure what this means? Click here to learn what changesets are.

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

@Calyhre
Copy link
Collaborator

Calyhre commented Oct 23, 2024

We have the same issue on our side, and this patch seems to solve it 👍

Copy link
Collaborator

@dylans dylans left a comment

Choose a reason for hiding this comment

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

Ok, this looks reasonable. Obviously if it causes any major regressions we may need to revert it.

@dylans dylans merged commit e97a9f8 into ianstormtaylor:main Oct 24, 2024
10 checks passed
@github-actions github-actions bot mentioned this pull request Oct 24, 2024
RavenColEvol pushed a commit to RavenColEvol/slate that referenced this pull request Mar 16, 2025
…mtaylor#5694. (ianstormtaylor#5746)

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

* Add patch changeset

* Catch additional invalide reference on Android
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

3 participants