[lexical-yjs] Bug Fix: handle text node being split by Yjs redo #7098
+278
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes a bug in
applyChildrenYjsDelta
which caused Lexical and Yjs to get out of sync. Once in this state, some changes would not sync to other clients; the changes would be lost on refresh.This can be reproduced in the Playground with the following steps:
When applying change deltas from Yjs, an
insertDelta
can be a string or asharedType
. IfcurrIndex
is pointing to some position within a text node andinsertDelta
is a string, then the new text is spliced in correctly. IfinsertDelta
represents a shared type, then the newly createdcollabNode
is inserted in the wrong position (before said text node).This PR updates the logic in
applyChildrenYjsDelta
to handle inserting asharedType
node in the middle of a text node.Test plan
The repro steps above are covered in an end-to-end test. I added a second E2E test to cover the case where the first
insertDelta
corresponds to anElementNode
, then the second delta is theTextNode
.Before
Lexical.applyChildrenYjsDelta.before.mov
After
Lexical.applyChildrenYjsDelta.after.mov