Skip to content

[lexical-yjs][lexical-react] Bug Fix: collab initialEditorState is no longer undoable - #8966

Closed
LeSingh1 wants to merge 1 commit into
facebook:mainfrom
LeSingh1:fix/collab-initial-state-undo
Closed

[lexical-yjs][lexical-react] Bug Fix: collab initialEditorState is no longer undoable#8966
LeSingh1 wants to merge 1 commit into
facebook:mainfrom
LeSingh1:fix/collab-initial-state-undo

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

When CollaborationPlugin bootstraps an empty shared document it writes initialEditorState through a normal editor update, which syncs into Yjs with the binding as the transaction origin. createUndoManager tracks 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 with HISTORY_MERGE_TAG and 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 isBootstrapping flag to the binding and has createUndoManager pass a captureTransaction that skips transactions produced while it is set. Both the V1 and V2 bootstrap paths go through a shared bootstrapEditor helper that raises it.

The flag is cleared from a microtask rather than a finally, because editor.update commits — 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: true on 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

… 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.
@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

@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.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 8, 2026
@LeSingh1

Copy link
Copy Markdown
Contributor Author

Consolidated into #9057 with the other PRs that share this defect, per @etrepum's note on #9027 and @mayrang's on #9035. Same fix and same tests, one review.

@LeSingh1 LeSingh1 closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: CollaborationPlugin's initialState can be undoed

1 participant