Repository navigation
[lexical-y] Bug Fix: Keep a rewrite's unchanged characters next to a word that was a node of its own - #9522
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
zurfyx
requested review from
acywatson,
etrepum,
ivailop7 and
potatowagon
as code owners
October 29, 2026 02:57
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/y
@lexical/yjs
commit: |
zurfyx
force-pushed
the
zurfyx/y-keep-chars-at-format-boundary
branch
from
October 29, 2026 05:32
cc442e2 to
3638f93
Compare
zurfyx
changed the base branch from
main
to
zurfyx/write-before-unread-change
October 29, 2026 05:33
This was referenced Oct 29, 2026
Merged
This was referenced Oct 29, 2026
vjeux
approved these changes
Oct 29, 2026
zurfyx
force-pushed
the
zurfyx/write-before-unread-change
branch
from
October 29, 2026 17:35
334bfea to
2dd6321
Compare
zurfyx
force-pushed
the
zurfyx/y-keep-chars-at-format-boundary
branch
from
October 29, 2026 17:51
3638f93 to
eabc52e
Compare
zurfyx
changed the base branch from
zurfyx/write-before-unread-change
to
main
October 29, 2026 17:51
…word that was a node of its own
## Description
When a line's children are made again as one node with one word changed
(an agent's block rewrite), `@lexical/y` wrote some unchanged characters
again as new text, if the changed word had been a text node of its own (for
example italic). A collaborator's concurrent edit of that word then landed
inside the word before it, on every client:
- `"t16z "` | _`"t63z "`_ | `" t19z"`, rewritten as one plain node with
`t63z` changed to `t80z`, wrote `"z t80z "` instead of `"t80z "`. A
collaborator who replaced `t63z` with `t83z` at the same time got
`"t16t83zz t80z t19z"`.
- The same happens when the dropped node is the last one (_`"t58z t59z"`_ |
`" t60z t61z"` rewrote the `z` of `t59z`), and with an IME composition in
the rewritten line.
The cause is in how a line's characters are matched. A removed node's text
is matched whole or not at all, so the italic `"t63z "` is deleted whole and
the old text is matched without it, as `"t16z t19z"`. The final check keeps
only what a second diff, which takes the common end first, keeps too. Over
that shortened text, the second diff read the change as `"z t80"` inserted
inside `t16z`. It disagreed with the first diff about the `z `, and the
check dropped it.
The check now also reads the old text as it was, with the text deleted whole
still in place, wherever the shortened text left some out. A character
either reading keeps the same way is kept. The change can only keep more
than before, and only where a removed node's text was deleted whole.
Elsewhere the stored bytes are unchanged.
## Changeset
`.changeset/lexical-y-keep-chars-at-format-boundary.md`: `[fix]` for
`@lexical/y`, with a `Verify:` paragraph.
## Test plan
New regression cases in
`packages/lexical-y/src/__tests__/unit/regressions/TextIdentity.test.ts`:
three line shapes, each in both client orders. Each checks the rewrite's own
deleted and inserted text, and that the text before the changed node stays
whole on every client and in a fresh read.
### Before
```
$ npx vitest --project unit --no-watch packages/lexical-y/src/__tests__/unit/regressions/TextIdentity.test.ts -t "S7-39"
Test Files 1 failed (1)
Tests 6 failed | 95 skipped (101)
AssertionError: expected { del: 'z t63z ', ins: 'z t80z ' } to deeply equal { del: 't63z ', ins: 't80z ' }
AssertionError: expected { del: ' cd ', ins: ' gh ' } to deeply equal { del: 'cd ', ins: 'gh ' }
- "del": " t60z t61z",
- "ins": " t70z t61z",
+ "del": "z t60z t61z",
+ "ins": "z t70z t61z",
```
### After
```
$ npx vitest --project unit --no-watch packages/lexical-y/src/__tests__/unit/regressions/TextIdentity.test.ts -t "S7-39"
Tests 6 passed | 95 skipped (101)
$ npx vitest --project unit --no-watch --maxWorkers=7 packages/lexical-y
Test Files 148 passed | 2 skipped (150)
Tests 4919 passed | 16 expected fail | 2 skipped (4937)
$ pnpm run ci-check
Changeset check passed: 5 pending changeset(s) valid.
Found 0 errors
```
I also ran randomized text-identity sessions from earlier reviews (a local
harness, not committed): 1,000 seeds of whole-node sets and swaps, 1,000 of
sets with made nodes, and 800 of plugin, agent and paste sessions. Every
summary and failure list matched main. The stored document state matched
main in all 783 sessions that are deterministic across two runs of main. A
replay of a randomized IME session that showed this bug (a composed word
landing inside the word before it) no longer does. Browser e2e was not
run.
zurfyx
force-pushed
the
zurfyx/y-keep-chars-at-format-boundary
branch
from
October 29, 2026 17:54
eabc52e to
f45dfa2
Compare
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.
Note
Stack, part 3 of 10. Based on #9523 (
zurfyx/write-before-unread-change). Review only this PR's own commits.The
@lexical/yfixes touch the same writer, cursor, reader and binding internals, so they are one linear stack: each PR is based on the one below it, each conflict is resolved once, in the PR whose change causes it, and every CI run tests the real combination.Merge order: bottom first, #9509 → #9523 → #9522 → #9505 → #9508 → #9502 → #9504 → #9527 → #9507 → #9510. With squash merges, rebase the next PR onto
mainbefore merging it (git rebase --onto main <old base branch>).The stack
zurfyx/update-error-rollbackmainzurfyx/write-before-unread-changezurfyx/y-keep-chars-at-format-boundaryzurfyx/y-undo-member-closerzurfyx/y-initial-state-bindingzurfyx/y-reorder-intentzurfyx/y-preserve-unknown-attrszurfyx/y-move-keeps-unknown-fieldszurfyx/y-composition-holdbackzurfyx/y-incremental-read-marksFollow-ups for after the stack (not in it):
Unread(changes Yjs applied that the binding has not read) and [lexical-playground][lexical-website][lexical-y] Bug Fix: Hold back remote changes to the line being composed until the composition ends #9507'sHidden(changes held back while a line is composed) answer one question, and call sites combine them by hand. One owner module (isGone,isShown,attrOf/attrsOfand the write primitives), an item-level held overlay instead of thewas/nowmaps, and a lint or grep test that allows raw.deleted/getAttr(s)only in the Reader and in named provenance scans. [lexical-website][lexical-y] Bug Fix: Stop a format, comment or link from spreading to the end of the document after an undo or delete races an edit inside it #9505's run-opener scans (liveItemBefore,runOpener,restatedEnd) still read raw deletedness and move there too.$groupReference,$priorGroupItem, the nearest neighbour's marker before the write,priorGroupMarker), with separate predecessor stores for markers and nodes. One stored-predecessor lookup would replace it.Description
When a line's children are made again as one node with one word changed
(an agent's block rewrite),
@lexical/ywrote some unchanged charactersagain as new text, if the changed word had been a text node of its own (for
example italic). A collaborator's concurrent edit of that word then landed
inside the word before it, on every client:
"t16z "|"t63z "|" t19z", rewritten as one plain node witht63zchanged tot80z, wrote"z t80z "instead of"t80z ". Acollaborator who replaced
t63zwitht83zat the same time got"t16t83zz t80z t19z"."t58z t59z"|" t60z t61z"rewrote thezoft59z), and with an IME composition inthe rewritten line.
The cause is in how a line's characters are matched. A removed node's text
is matched whole or not at all, so the italic
"t63z "is deleted whole andthe old text is matched without it, as
"t16z t19z". The final check keepsonly what a second diff, which takes the common end first, keeps too. Over
that shortened text, the second diff read the change as
"z t80"insertedinside
t16z. It disagreed with the first diff about thez, and thecheck dropped it.
The check now also reads the old text as it was, with the text deleted whole
still in place, wherever the shortened text left some out. A character
either reading keeps the same way is kept. The change can only keep more
than before, and only where a removed node's text was deleted whole.
Elsewhere the stored bytes are unchanged.
Restack (October 29)
Rebased onto #9523 with no conflicts. It adds no raw attribute or deletedness reads on the write path, so nothing here changes for #9523's view.
Changeset
.changeset/lexical-y-keep-chars-at-format-boundary.md:[fix]for@lexical/y, with aVerify:paragraph.Test plan
New regression cases in
packages/lexical-y/src/__tests__/unit/regressions/TextIdentity.test.ts:three line shapes, each in both client orders. Each checks the rewrite's own
deleted and inserted text, and that the text before the changed node stays
whole on every client and in a fresh read.
Before
After
I also ran randomized text-identity sessions from earlier reviews (a local
harness, not committed): 1,000 seeds of whole-node sets and swaps, 1,000 of
sets with made nodes, and 800 of plugin, agent and paste sessions. Every
summary and failure list matched main. The stored document state matched
main in all 783 sessions that are deterministic across two runs of main. A
replay of a randomized IME session that showed this bug (a composed word
landing inside the word before it) no longer does. Browser e2e was not
run.