Repository navigation
[lexical-playground][lexical-react] Bug Fix: only one collab client bootstraps a nested editor's document - #9107
Merged
etrepum merged 6 commits intoAug 31, 2026
Conversation
…ootstraps a nested editor's document
## Description
`ImageComponent` (image caption) and `StickyComponent` (sticky note) mount
`CollaborationPlugin` with `shouldBootstrap={true}` unconditionally, while the
main document uses `shouldBootstrap={!skipCollaborationInit}` so that only the
`left` frame of the `/split/` two-client view seeds it.
That is unsafe for a nested editor. `syncPropertiesToYjs` gives the nested
editor a sub-`Doc` and uses that doc's `guid` as the editor key, so every client
resolves the same collab room -- and unlike the main document, every client
mounts the nested editor at the same moment the node itself syncs. Bootstrap is
an ordinary Yjs insert rather than a compare-and-set, so when both clients'
`sync` arrives before either's paragraph has propagated, each inserts an empty
paragraph and Yjs keeps both. The caption ends up with a leading empty
paragraph and the user's text in the second one, which is what made
`SelectBlock › Select within nested editor` fail intermittently in the collab
e2e job:
Array [
3, 1, 1, 0,
- 0,
+ 1,
0, 0,
]
`skipCollaborationInit` moves from `App.tsx` to `collaboration.ts` so both
nested editors can share it, and `CollaborationPlugin`'s `shouldBootstrap` prop
gains a doc comment recording that at most one client may set it.
## Test plan
### Before
`SelectBlock › Select within nested editor`, collab mode, 40 repeats over 8
workers on a 4-core box (oversubscribed to widen the race):
Error: expect(received).toEqual(expected) // deep equality
- Expected - 1
+ Received + 1
Array [
3,
1,
1,
0,
- 0,
+ 1,
0,
0,
]
at assertSelectionOnPageOrFrame (packages/lexical-playground/__tests__/utils/index.mjs:660:32)
1 failed
39 passed (3.3m)
A reduced spec asserting the caption editor's HTML directly, 24 repeats over 8
workers, caught the extra paragraph itself:
Expected: "<p class=\"PlaygroundEditorTheme__paragraph\" dir=\"auto\"><span data-lexical-text=\"true\">caption text</span></p>"
Received: "<p class=\"PlaygroundEditorTheme__paragraph\" dir=\"auto\"><br data-lexical-managed-linebreak=\"true\"></p><p class=\"PlaygroundEditorTheme__paragraph\" dir=\"auto\"><span data-lexical-text=\"true\">caption text</span></p>"
Instrumenting `onBootstrap` showed both frames on the same caption document,
with the second frame only just losing the race:
DBG onBootstrap {"_f":"left","id":"a421fdae-b83b-4706-8283-b7761fdff588","shouldBootstrap":true,"yEmpty":true,"len":0}
DBG bootstrap:initializeEditor {"_f":"left","empty":true,"hasSel":true,"active":true,"size":0}
DBG onBootstrap {"_f":"right","id":"a421fdae-b83b-4706-8283-b7761fdff588","shouldBootstrap":true,"yEmpty":false,"len":1}
### After
Same test, same oversubscribed configuration, 58 repeats completed with no
failures before the run was stopped:
Running 100 tests using 8 workers
✓ ... SelectBlock › Select within nested editor
(58 completed, 0 failed)
Full `SelectBlock.spec.mjs` and `Images.spec.mjs` in collab mode:
4 skipped
23 passed (1.5m)
`pnpm run tsc`, `npx prettier --list-different` and `npx eslint` are clean on
the changed files. Only chromium was exercised; firefox and webkit were not run
in this environment.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
marked this pull request as ready for review
August 31, 2026 06:04
etrepum
requested review from
acywatson,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 31, 2026 06:04
Merged
…sted editor selection test
## Description
`Selection › keeps single active selection for nested editors` reads both
editors' `_selection` once, immediately after `focusEditor()`. Focusing an
editor only moves the DOM selection; ownership moves when Lexical handles the
`selectionchange` the browser dispatches for it, and that dispatch is
asynchronous. The one-shot read races the handover, so the test can observe the
moment where the DOM selection already sits inside the newly focused editor
while both editors still hold their previous Lexical state -- the caption
editor's selection still `null` and the root editor's still set.
Instrumenting the failing step shows the DOM is already correct when the
assertion fails, and that the handover lands on the very next round trip:
P5 after focus caption {"activeEl":"<div.ImageNode__contentEditable>",
"activeIsCaption":true,"caption":{"hasSel":false},
"domAnchor":"#text(\"Hello world\")","domAnchorInCaption":true,
"root":{"hasSel":true,"key":"49","offset":0}}
P6 ms until caption selection 0 immediate false
The race is only wide enough to lose in collab mode, where the split view runs
two clients and the extra work delays the event past the read; the same test on
the same browser never failed in non-collab mode.
Both assertions in each pair now go through one `expect.poll` over the pair, so
the editor losing the selection is checked against the same handover the
winning editor waits for. No source change -- this is a test synchronization
fix.
## Test plan
### Before
`Selection › keeps single active selection for nested editors`, webkit, 32
repeats over 8 workers on a 4-core box (oversubscribed to widen the race):
Error: expect(received).toBe(expected) // Object.is equality
Expected: true
Received: false
136 | expect(await hasSelection('.image-caption-container')).toBe(true);
| ^
14 failed
18 passed (3.4m)
Failures split 13 at line 136 (caption never takes the selection) and 1 at line
126 (root editor has not taken it back yet) -- the same race in both
directions. The identical run in non-collab mode passed 32/32, which is what
pinned the cause to timing rather than to WebKit focus handling.
### After
Same test, same oversubscribed configuration:
32 passed (3.1m)
Across every browser and mode that runs this test, 8 repeats each:
=== webkit rich-text 8 passed (20.9s)
=== webkit rich-text-with-collab 8 passed (41.7s)
=== chromium rich-text 8 passed (18.2s)
=== chromium rich-text-with-collab 8 passed (25.8s)
=== firefox rich-text 8 passed (27.8s)
=== firefox rich-text-with-collab 8 passed (38.2s)
Full `Selection.spec.mjs` in webkit collab:
31 skipped
27 passed (2.2m)
`npx prettier --list-different` and `npx eslint` are clean on the changed file.
Linux WebKit was used here rather than the macOS WebKit the CI job runs.
…est-g0qr23' into claude/nested-editor-selection-test-g0qr23
zurfyx
approved these changes
Aug 31, 2026
This branch was successfully deployed
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.
Description
ImageComponent(image caption) andStickyComponent(sticky note) mountCollaborationPluginwithshouldBootstrap={true}unconditionally, while the main document usesshouldBootstrap={!skipCollaborationInit}so that only theleftframe of the/split/two-client view seeds it.That is unsafe for a nested editor.
syncPropertiesToYjsgives the nested editor a sub-Docand uses that doc'sguidas the editor key, so every client resolves the same collab room -- and unlike the main document, every client mounts the nested editor at the same moment the node itself syncs. Bootstrap is an ordinary Yjs insert rather than a compare-and-set, so when both clients'syncarrives before either's paragraph has propagated, each inserts an empty paragraph and Yjs keeps both. The caption ends up with a leading empty paragraph and the user's text in the second one, which is what madeSelectBlock › Select within nested editorfail intermittently in the collab e2e job:skipCollaborationInitmoves fromApp.tsxtocollaboration.tsso both nested editors can share it, andCollaborationPlugin'sshouldBootstrapprop gains a doc comment recording that at most one client may set it.Test plan
Before
SelectBlock › Select within nested editor, collab mode, 40 repeats over 8 workers on a 4-core box (oversubscribed to widen the race):A reduced spec asserting the caption editor's HTML directly, 24 repeats over 8 workers, caught the extra paragraph itself:
Instrumenting
onBootstrapshowed both frames on the same caption document, with the second frame only just losing the race:After
Same test, same oversubscribed configuration, 58 repeats completed with no failures before the run was stopped:
Full
SelectBlock.spec.mjsandImages.spec.mjsin collab mode:pnpm run tsc,npx prettier --list-differentandnpx eslintare clean on the changed files. Only chromium was exercised; firefox and webkit were not run in this environment.