Repository navigation
[lexical-yjs] Bug Fix: Write a collab v2 slot edit to Yjs after a remote change next to its host - #9376
Closed
zurfyx wants to merge 1 commit into
Closed
[lexical-yjs] Bug Fix: Write a collab v2 slot edit to Yjs after a remote change next to its host#9376zurfyx wants to merge 1 commit into
zurfyx wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…ote change next to its host
## Description
With collab v2, after a peer inserts a block right before or after a host
node that has named slots (or removes the host's neighbour), the receiving
peer's next edit inside one of that host's slots is never written to its
Yjs document. The edit shows locally but never reaches the other peers, and
is lost if the editor is closed before another edit in the same slot
re-sends the full text. No concurrency is needed.
Applying the remote change clones the host on the receiving peer (its
`__prev`/`__next` change), so the host no longer passes the identity check in
`$updateYFragment` and falls back to the structural `$equalYTypePNode`. For
the children channel that comparison is deep, but `$equalSlots` only checked
that the slot's shared type maps to the slot root node. Typing in a slot's
paragraph clones the text node, not the slot root, so the slot compared equal,
the host's mapping was repointed, and the dirty slot was never visited.
`$equalSlots` now compares each slot like the children channel: the slot node
must map to that shared type and `$equalYTypePNode` must report its subtree
equal. A false negative only costs a recursion into the host, which then
diffs its slots in place through `$updateSlotsYType`.
## Test plan
New `packages/lexical-yjs/src/__tests__/unit/SlotSyncV2Peers.test.ts` wires
two v2 peers like `useYjsCollaborationV2` (observer for remote changes,
update listener for local ones) over a synchronous in-memory transport. Peer
A changes a sibling of a slotted host, then peer B types one character in the
host's slot; the test checks B's own Yjs document and A's editor. A control
case edits the slot without changing the host's siblings.
### Before
```
$ npx vitest --project unit --no-watch packages/lexical-yjs/src/__tests__/unit/SlotSyncV2Peers.test.ts
❯ |unit| packages/lexical-yjs/src/__tests__/unit/SlotSyncV2Peers.test.ts (4 tests | 3 failed) 47ms
× a slot edit after a remote change of a paragraph inserted right before the host is written to yjs 30ms
× a slot edit after a remote change of a paragraph inserted right after the host is written to yjs 5ms
× a slot edit after a remote change of the host's previous sibling removed is written to yjs 5ms
✓ a slot edit with an unchanged host sibling list is written to yjs (control) 5ms
AssertionError: expected 'cap text' to be 'Ycap text' // Object.is equality
Expected: "Ycap text"
Received: "cap text"
❯ packages/lexical-yjs/src/__tests__/unit/SlotSyncV2Peers.test.ts:270:37
268| expect(readCaption(b.editor)).toBe('Ycap text');
269| // Written to B's own yjs doc...
270| expect(yjsCaption(b.binding)).toBe('Ycap text');
Test Files 1 failed (1)
Tests 3 failed | 1 passed (4)
```
### After
```
$ npx vitest --project unit --no-watch packages/lexical-yjs/src/__tests__/unit/SlotSyncV2Peers.test.ts
✓ |unit| packages/lexical-yjs/src/__tests__/unit/SlotSyncV2Peers.test.ts (4 tests) 48ms
Test Files 1 passed (1)
Tests 4 passed (4)
$ npx vitest --project unit --no-watch packages/lexical-yjs packages/lexical-react/src/__tests__/unit/Collab* packages/lexical-react/src/__tests__/unit/LexicalCollaborationPlugin.test.tsx
Test Files 17 passed (17)
Tests 174 passed (174)
```
`pnpm run test-unit`: 393 files, 9541 tests passed (1 skipped).
`pnpm run tsc`, `pnpm run flow` (0 errors), ESLint and Prettier on the
changed files pass.
Run headless in Node/jsdom with an in-memory
transport only; not exercised in a real browser or over a real provider.
zurfyx
force-pushed
the
zurfyx/collab-v2-slot-sync
branch
from
October 22, 2026 14:14
47b16c0 to
9a772cf
Compare
zurfyx
marked this pull request as ready for review
October 22, 2026 14:14
zurfyx
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7 and
potatowagon
as code owners
October 22, 2026 14:14
lexical
@lexical/a11y
@lexical/clipboard
@lexical/code
@lexical/code-core
@lexical/code-prism
@lexical/code-shiki
@lexical/compiler
@lexical/devtools-core
@lexical/dragon
@lexical/eslint-plugin
@lexical/extension
@lexical/fast-check
@lexical/file
@lexical/hashtag
@lexical/headless
@lexical/history
@lexical/html
@lexical/internal
@lexical/link
@lexical/list
@lexical/mark
@lexical/markdown
@lexical/mdast
@lexical/offset
@lexical/overflow
@lexical/plain-text
@lexical/react
@lexical/rich-text
@lexical/selection
@lexical/table
@lexical/tailwind
@lexical/text
@lexical/utils
@lexical/yjs
commit: |
potatowagon
approved these changes
Oct 22, 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
With collab v2, after a peer inserts a block right before or after a host
node that has named slots (or removes the host's neighbour), the receiving
peer's next edit inside one of that host's slots is never written to its
Yjs document. The edit shows locally but never reaches the other peers, and
is lost if the editor is closed before another edit in the same slot
re-sends the full text. No concurrency is needed.
Applying the remote change clones the host on the receiving peer (its
__prev/__nextchange), so the host no longer passes the identity check in$updateYFragmentand falls back to the structural$equalYTypePNode. Forthe children channel that comparison is deep, but
$equalSlotsonly checkedthat the slot's shared type maps to the slot root node. Typing in a slot's
paragraph clones the text node, not the slot root, so the slot compared equal,
the host's mapping was repointed, and the dirty slot was never visited.
$equalSlotsnow compares each slot like the children channel: the slot nodemust map to that shared type and
$equalYTypePNodemust report its subtreeequal. A false negative only costs a recursion into the host, which then
diffs its slots in place through
$updateSlotsYType.Test plan
New
packages/lexical-yjs/src/__tests__/unit/SlotSyncV2Peers.test.tswirestwo v2 peers like
useYjsCollaborationV2(observer for remote changes,update listener for local ones) over a synchronous in-memory transport. Peer
A changes a sibling of a slotted host, then peer B types one character in the
host's slot; the test checks B's own Yjs document and A's editor. A control
case edits the slot without changing the host's siblings.
Before
After
pnpm run test-unit: 393 files, 9541 tests passed (1 skipped).pnpm run tsc,pnpm run flow(0 errors), ESLint and Prettier on thechanged files pass.
Run headless in Node/jsdom with an in-memory
transport only; not exercised in a real browser or over a real provider.