-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
onDOMSelectionChange causes crash during concurrent updates #5694
Labels
Comments
DustinMackintosh
added a commit
to DustinMackintosh/slate
that referenced
this issue
Oct 18, 2024
DustinMackintosh
added a commit
to DustinMackintosh/slate
that referenced
this issue
Oct 18, 2024
5 tasks
Thank you for your write up, @gblaketx, it was invaluable in helping me when I encountered this same issue. Hoping we can get some attention on my proposed fix. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
The editor can crash if the user is typing while other updates are being applied (for instance, applying remote user updates or automated edits). The user's typing triggers an
onDOMSelectionChange
call, but the selection update from this function is stale, which can cause the cursor to jump or crash the editor.Recording
https://github.com/user-attachments/assets/a68453b1-df47-4324-a542-9313569958ca
Sandbox
https://codesandbox.io/s/slate-selection-change-repro-ztssmp
Steps
To reproduce the behavior:
Expectation
Basic concurrent updates shouldn't crash the editor. In the example posted, the user should be able to continue to type on the last line while new lines are added above.
Environment
Context
I suspect the root cause of this issue is a stale
NODE_TO_INDEX
weak map. Because that map is updated after nodes rerender, if the editor content changes and a selection event fires before a re-render, the map can be stale.Looking at the code, the sequence of events is:
The text was updated successfully, but these errors were encountered: