[lexical-yjs][lexical-react] Bug Fix: collab initialEditorState is no longer undoable - #8966
Closed
LeSingh1 wants to merge 1 commit into
Closed
[lexical-yjs][lexical-react] Bug Fix: collab initialEditorState is no longer undoable#8966LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
… longer undoable When CollaborationPlugin bootstraps an empty shared document it writes initialEditorState through a normal editor update, which syncs to Yjs under the binding origin. That origin is tracked by the UndoManager, so the very first undo removed the initial content. A non-collab editor applies its initial state with HISTORY_MERGE_TAG and it is never undoable, so collab was inconsistent. Flag the binding while the bootstrap write is in flight and have createUndoManager pass a captureTransaction that skips transactions produced during it. The flag is cleared from a microtask because the editor update commits (and therefore syncs to Yjs) in one; clearing it there rather than from the commit means it cannot get stuck if the bootstrap update is a no-op.
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 8, 2026 00:14
|
@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When
CollaborationPluginbootstraps an empty shared document it writesinitialEditorStatethrough a normal editor update, which syncs into Yjs with the binding as the transaction origin.createUndoManagertracks that origin, so the bootstrap becomes the first undo stack item and the very first undo wipes the initial content. A non-collab editor applies its initial state withHISTORY_MERGE_TAGand it is never undoable, so collab behaved inconsistently — and content that is meant to be fixed layout can be removed entirely by the user.This adds an
isBootstrappingflag to the binding and hascreateUndoManagerpass acaptureTransactionthat skips transactions produced while it is set. Both the V1 and V2 bootstrap paths go through a sharedbootstrapEditorhelper that raises it.The flag is cleared from a microtask rather than a
finally, becauseeditor.updatecommits — and therefore syncs to Yjs — in a microtask that Lexical has already queued. Clearing it there rather than from the commit also means it cannot get stuck if the bootstrap update is a no-op.For the record I first tried
discrete: trueon the bootstrap update instead. It fixed the new test but broke 19 existing collab tests by changing bootstrap interleaving, so I dropped that approach.Adds a unit test that bootstraps an initial state and then undoes; it fails on
main.Fixes #7110