[lexical-y] Bug Fix: Keep a line marker with the line that continues the line it ended #9860
[vc]: #Jz0hHWTEa34fsQ4FF8nfjKKGlWRTRh54pq6UxY4ZzO4=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJsZXhpY2FsLXBsYXlncm91bmQiLCJwcm9qZWN0SWQiOiJwcmpfZWE4MnZMajY4NFh6U1JkZU83SlNkMFFOa2F3cyIsInYwIjpmYWxzZSwicm9vdERpcmVjdG9yeSI6InBhY2thZ2VzL2xleGljYWwtcGxheWdyb3VuZCIsImluc3BlY3RvclVybCI6Imh0dHBzOi8vdmVyY2VsLmNvbS9mYm9wZW5zb3VyY2UvbGV4aWNhbC1wbGF5Z3JvdW5kLzQ1cTNvMlA4d0xqaXNmOUR4enYzeGJlNVJDWGQiLCJwcmV2aWV3VXJsIjoibGV4aWNhbC1wbGF5Z3JvdW5kLWdpdC16dXJmeXgteS1tYXJrZXItaWRlbnRpdHktZmJvcGVuc291cmNlLnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiREVQTE9ZRUQifSx7Im5hbWUiOiJsZXhpY2FsIiwicHJvamVjdElkIjoicHJqX01SYU1PMzFlRklrWTYxU0JxcVBEUjJPank4cVAiLCJ2MCI6ZmFsc2UsInJvb3REaXJlY3RvcnkiOiJwYWNrYWdlcy9sZXhpY2FsLXdlYnNpdGUiLCJpbnNwZWN0b3JVcmwiOiJodHRwczovL3ZlcmNlbC5jb20vZmJvcGVuc291cmNlL2xleGljYWwvM3BGMms5aEtRNmpmcmU4cnJjWlBram1GQmNDQiIsInByZXZpZXdVcmwiOiJsZXhpY2FsLWdpdC16dXJmeXgteS1tYXJrZXItaWRlbnRpdHktZmJvcGVuc291cmNlLnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiREVQTE9ZRUQifV0sInJlcXVlc3RSZXZpZXdVcmwiOiJodHRwczovL3ZlcmNlbC5jb20vdmVyY2VsLWFnZW50L3JlcXVlc3QtcmV2aWV3P293bmVyPW1ldGEmcmVwbz1sZXhpY2FsJnByPTk4NjAifQ==
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Actions | Updated |
| :--- | :----- | :------ | :------ |
| <a href="https://vercel.com/fbopensource/lexical"><sup><img src="https://vercel.com/api/www/avatar?projectId=prj_MRaMO31eFIkY61SBqqPDR2Ojy8qP&teamId=team_QNIQyH5DJlqUjeCckcCcBEjE&s=32" width="16" height="16" align="middle" alt="" /></sup></a> lexical | !Ready Ready | Preview | <relative-time datetime="2026-11-10T10:22:06.189Z">Nov 10, 2026 10:22am UTC</relative-time> |
| <a href="https://vercel.com/fbopensource/lexical-playground"><sup><img src="https://vercel.com/api/www/avatar?projectId=prj_ea82vLj684XzSRdeO7JSd0QNkaws&teamId=team_QNIQyH5DJlqUjeCckcCcBEjE&s=32" width="16" height="16" align="middle" alt="" /></sup></a> lexical-playground | !Ready Ready | Preview | <relative-time datetime="2026-11-10T10:22:06.189Z">Nov 10, 2026 10:22am UTC</relative-time> |
<a href="https://vercel.com/vercel-agent/request-review?owner=meta&repo=lexical&pr=9860" rel="noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://agents-vade-review.vercel.sh/request-review-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://agents-vade-review.vercel.sh/request-review-light.svg"><img src="https://agents-vade-review.vercel.sh/request-review-light.svg" alt="Request Review"></picture></a>
AI review status for this pull request.
| Review status | Updated |
| :--- | :--- |
| 🟢 Reviewed (for maintainers only) | <relative-time datetime="2026-11-10T10:41:46Z">Nov 10, 2026, 10:41 AM UTC</relative-time> |
<!-- codebunny-status:1 r=318341089 p=9860 rv=2 -->
<details><summary><b>lexical</b></summary><p>
npm i https://pkg.pr.new/lexical@9860
</p></details>
<details><summary><b>@lexical/a11y</b></summary><p>
npm i https://pkg.pr.new/@lexical/a11y@9860
</p></details>
<details><summary><b>@lexical/clipboard</b></summary><p>
npm i https://pkg.pr.new/@lexical/clipboard@9860
</p></details>
<details><summary><b>@lexical/code</b></summary><p>
npm i https://pkg.pr.new/@lexical/code@9860
</p></details>
<details><summary><b>@lexical/code-core</b></summary><p>
npm i https://pkg.pr.new/@lexical/code-core@9860
</p></details>
<details><summary><b>@lexical/code-prism</b></summary><p>
npm i https://pkg.pr.new/@lexical/code-prism@9860
</p></details>
<details><summary><b>@lexical/code-shiki</b></summary><p>
npm i https://pkg.pr.new/@lexical/code-shiki@9860
</p></details>
<details><summary><b>@lexical/compiler</b></summary><p>
npm i https://pkg.pr.new/@lexical/compiler@9860
</p></details>
<details><summary><b>@lexical/devtools-core</b></summary><p>
npm i https://pkg.pr.new/@lexical/devtools-core@9860
</p></details>
<details><summary><b>@lexical/dragon</b></summary><p>
npm i https://pkg.pr.new/@lexical/dragon@9860
</p></details>
<details><summary><b>@lexical/eslint-plugin</b></summary><p>
npm i https://pkg.pr.new/@lexical/eslint-plugin@9860
</p></details>
<details><summary><b>@lexical/extension</b></summary><p>
npm i https://pkg.pr.new/@lexical/extension@9860
</p></details>
<details><summary><b>@lexical/fast-check</b></summary><p>
npm i https://pkg.pr.new/@lexical/fast-check@9860
</p></details>
<details><summary><b>@lexical/file</b></summary><p>
npm i https://pkg.pr.new/@lexical/file@9860
</p></details>
<details><summary><b>@lexical/hashtag</b></summary><p>
npm i https://pkg.pr.new/@lexical/hashtag@9860
</p></details>
<details><summary><b>@lexical/headless</b></summary><p>
npm i https://pkg.pr.new/@lexical/headless@9860
</p></details>
<details><summary><b>@lexical/history</b></summary><p>
npm i https://pkg.pr.new/@lexical/history@9860
</p></details>
<details><summary><b>@lexical/html</b></summary><p>
npm i https://pkg.pr.new/@lexical/html@9860
</p></details>
<details><summary><b>@lexical/internal</b></summary><p>
npm i https://pkg.pr.new/@lexical/internal@9860
</p></details>
<details><summary><b>@lexical/link</b></summary><p>
npm i https://pkg.pr.new/@lexical/link@9860
</p></details>
<details><summary><b>@lexical/list</b></summary><p>
npm i https://pkg.pr.new/@lexical/list@9860
</p></details>
<details><summary><b>@lexical/mark</b></summary><p>
npm i https://pkg.pr.new/@lexical/mark@9860
</p></details>
<details><summary><b>@lexical/markdown</b></summary><p>
npm i https://pkg.pr.new/@lexical/markdown@9860
</p></details>
<details><summary><b>@lexical/mdast</b></summary><p>
npm i https://pkg.pr.new/@lexical/mdast@9860
</p></details>
<details><summary><b>@lexical/offset</b></summary><p>
npm i https://pkg.pr.new/@lexical/offset@9860
</p></details>
<details><summary><b>@lexical/overflow</b></summary><p>
npm i https://pkg.pr.new/@lexical/overflow@9860
</p></details>
<details><summary><b>@lexical/plain-text</b></summary><p>
npm i https://pkg.pr.new/@lexical/plain-text@9860
</p></details>
<details><summary><b>@lexical/react</b></summary><p>
npm i https://pkg.pr.new/@lexical/react@9860
</p></details>
<details><summary><b>@lexical/rich-text</b></summary><p>
npm i https://pkg.pr.new/@lexical/rich-text@9860
</p></details>
<details><summary><b>@lexical/selection</b></summary><p>
npm i https://pkg.pr.new/@lexical/selection@9860
</p></details>
<details><summary><b>@lexical/table</b></summary><p>
npm i https://pkg.pr.new/@lexical/table@9860
</p></details>
<details><summary><b>@lexical/tailwind</b></summary><p>
npm i https://pkg.pr.new/@lexical/tailwind@9860
</p></details>
<details><summary><b>@lexical/text</b></summary><p>
npm i https://pkg.pr.new/@lexical/text@9860
</p></details>
<details><summary><b>@lexical/utils</b></summary><p>
npm i https://pkg.pr.new/@lexical/utils@9860
</p></details>
<details><summary><b>@lexical/y</b></summary><p>
npm i https://pkg.pr.new/@lexical/y@9860
</p></details>
<details><summary><b>@lexical/yjs</b></summary><p>
npm i https://pkg.pr.new/@lexical/yjs@9860
</p></details>
_commit: <a href="https://github.com/meta/lexical/runs/129770342545"><code>6a6c75a</code></a>_
Must fix. This rule only gives the old marker to the tail of a split when the old line's last atom is a character. When the line ends with an inline decorator, byRecord is undefined, the line that kept its key (the head) claims the marker at 4154, and the head cannot keep it in place. The old marker item is deleted, and a collaborator's concurrent change to that line is lost on every client.
Repro: A presses Enter after hello in hello world <equation> while B, offline, centers the paragraph, converts it to h2, or indents it. On main the tail line keeps B's change; here it does not, in either client-id order.
$exactAtoms already maps kept inline nodes (place(j, 1, key, true)), so accepting them here brings back main's result for these cases while MarkerKeptByItsLine.test.ts still passes:
const byRecord =
oi >= 0 &&
(!old.specials.has(oi) || old.specials.get(oi)!.kind === 'oldNode')
? recorded.get(oi)
: undefined;
isNew is computed but never read. The description's rule 3 ("or the line is new") and rule 4 ("the tail of a split: a new line ending with what the old line, which stays, lost from its end") seem to be what it was for. Without them, a split Lexical's record does not explain (app code that calls setTextContent on the head and adds a paragraph holding the tail) deletes the old marker, and a collaborator's concurrent alignment on that line is lost. On main it lands on the tail.
Thanks for tracking this down. The two repros are real, and the new regression file proves the fix: it fails 8/8 on main and passes on this branch, and a blockconv lane run shows the three classes named in the description dropping. One regression needs fixing before this can merge, plus a few smaller follow-ups.
Must fix: a split now drops a collaborator's change to the line when the line ends with an inline node
packages/lexical-y/src/internal/Write.ts:4148-4149: the record rule only gives the old marker to the tail of a split when the old line's last atom is a character (!old.specials.has(oi)). When the line ends with an inline decorator (an equation, an image, a mention), the line that kept its key, which is the head, claims the marker. The head cannot keep it in place, because the marker sits after the tail's text. So the old marker item is deleted and two new markers are written, and whatever a collaborator wrote to that line at the same time is lost on every client.
Repro (both client-id orders; all peers and a fresh reader converge): A presses Enter after hello in hello world <equation>, while B, offline, centers that paragraph, converts it to h2, or indents it. On main the tail line ends up centered, a heading, or indented. On this branch none of the three survive. The same happens when app code splits the line with setTextContent('hello ') plus a new paragraph holding world, or by replacing the text node.
This contradicts D118 ("Split: the line holding the tail keeps the marker") and the description's statement that Enter stores the same as before. A possible fix: let the record rule accept a kept inline node as the old line's last atom. $exactAtoms already maps those (place(j, 1, key, true)), so a guard such as (!old.specials.has(oi) || old.specials.get(oi)!.kind === 'oldNode') brings back main's result for the decorator cases while MarkerKeptByItsLine.test.ts still passes. The app-code split also needs the split-by-text claim the description lists as rule 4 ("a new line ending with what the old line, which stays, lost from its end"). The code only matches text where the old line is gone, and isNew (line 4044) is computed but never read. packages/lexical-y/AGENTS.md asks that every bug fix land with a regression test in src/__tests__/unit/regressions/, so please add these repros there.
Consider
main it went to the added line). D118's "a line ending with all of its text (a paste over it)" does not hold in that case.KNOWN_OPEN in LaneFuzz.test.ts asks that a fix which reduces a class lower its per1000, and that the fix which brings it to zero remove the entry. Its triage note still says this fix is planned as a separate pull request. In a 400-history blockconv run, untouched-block-changed went from 8 to 0, ending-phase-other-block from 8 to 1, and ending-phase-text from 1 to 0.LANE_REPLAY=untouched.json and end-text.json files are not in the repository, so those runs cannot be replayed.Nits
@lexical/y (AGENTS.md "Changesets", .changeset/README.md): a [fix] entry with a Verify: paragraph, like the other pending @lexical/y fixes.enders map (Write.ts:4063-4071) is built on every multi-marker write, though only a line that is gone reads it. It could be built lazily, like $indexHolders.<!-- codebunny-pub:1 k=554d77ee601e33b2fc9a3fc0420cd4ca83790baa1015ce9237ea1781015b0ce7 -->
Consider (non-blocking). A split always puts the tail after the head, but this accepts any new line ending with what the line lost. App code that, in one update, sets hello world to hello and inserts a new paragraph world before it leaves the old marker claimable only by world; that marker is not anchored, so it is deleted, and a collaborator's concurrent centering or h2 of the line is lost on every client (main keeps it on hello , in both client-id orders). Limiting the claim to lines after the line gives that back and keeps MarkerKeptByItsLine.test.ts at 36/36:
? endingWith(tail).filter(
k => newLines[k].isNew && k > own[own.length - 1],
)
Consider (non-blocking). "or else by a line ending with all of its text (a paste over it)" does not hold when a line is added after the remade line: replace abc with a new paragraph abc and add xyz after it while a collaborator centers the line, and the marker is deleted (the record treats the remade text as new, so the prefix stops before the marker, and only record-placed markers become islands), so the centering is dropped on every client. main applied it to xyz. Either keep such a marker as an island, or narrow this sentence and add a test.fails for the case (packages/lexical-y/AGENTS.md, Testing).
This looks good to me. The marker fix is well targeted, and the new regression file shows it working: 16 of its 36 cells fail on main (the composed node moves into the added block, and a joined line's concurrent change lands on the added line), and all of them pass here. In every case I tried, Enter, Backspace and range deletes across lines store the same as on main, and both items from the earlier review are fixed. The suggestions below are optional and non-blocking.
Optional: limit the tail claim to new lines after the line (packages/lexical-y/src/internal/Write.ts:4185)
A split always puts the tail after the head, but this claim accepts any new line that ends with what the line lost. Say app code, in one update, sets hello world to hello and inserts a new paragraph world before it. Only world can then claim the old marker, and that marker is not anchored, so it is deleted. A collaborator's concurrent centering or heading of that line is then lost on every client. On main it stays on hello . This change keeps MarkerKeptByItsLine.test.ts passing and gives main's result back:
? endingWith(tail).filter(
k => newLines[k].isNew && k > own[own.length - 1],
)
Optional: D118's paste-over sentence (packages/lexical-y/DECISIONS.md:79)
D118 says a removed line's marker is kept "by a line ending with all of its text (a paste over it)". That does not hold when a line is added after the remade line. Replace abc with a new paragraph abc and add xyz after it while a collaborator centers the line: the marker is deleted and the centering is dropped (main applied it to xyz). Either keep such a marker as an island, or narrow the sentence.
Optional: cells for both cases. packages/lexical-y/AGENTS.md asks for a regression test in src/__tests__/unit/regressions/ with each fix, and a test.fails for a known failure. The run(...) harness in MarkerKeptByItsLine.test.ts covers both with two more calls.
<!-- codebunny-pub:1 k=d90c1b6c25073ff0009782c3796967d9304b7df355ad271310973235c561bef5 -->
Must fix. A line that stays and only grew at its end claims only its own marker here, but that marker can be kept only at the common prefix or suffix (the islands keep record-placed markers only). So two paragraphs pasted at the end of a line (RangeSelection.insertNodes), or app code that sets hello! and adds a paragraph after it, delete the old marker. A collaborator composing at the end of that line has the composed node detached mid-composition and sees the paste at once, where main holds the line (y.md, Limits, "Input method composition"). A concurrent Delete that joins it with the next line is dropped (helloA | B | next; main: helloA | Bnext), and so is a concurrent alignment or type change, in both client-id orders.
Falling back to position for that case restores main's result in all of these and keeps MarkerKeptByItsLine.test.ts and the regressions/ folder passing:
// A line that only grew at its end, with a new line after it (lines
// pasted at its end): by position, as before.
if (
n === was.length &&
head.length > was.length &&
newLines.some((x, k) => x.isNew && k > own[own.length - 1])
) {
best.set(i, ANY);
return;
}
set = new Set(tails.length > 0 ? tails : own);
Consider (non-blocking). On this branch the composed node ends detached here ($blockOf(key) is −1 in all four cells of this test and the next one), which .not.toBe(2) also accepts, although the title says the composition stays on the quote. Pinning the expected value would catch a change in either direction.
Consider (non-blocking). The node is detached on this branch, so this guard skips the block and z is never typed: "text typed as the composition ends stays in the code block" is not exercised, and the assertions below would pass with no typing at all. Asserting that the code block's text ends with z (or typing at the selection the composition end leaves) would cover it.
Consider (non-blocking). When many lines share their last 8 characters, each gone line's lookup filters every one of them. Remaking every line of a document whose lines all end in of the document takes about twice as long as on main (6,400 lines: about 2.0 s against 1.1 s; equal with distinct endings). A map keyed by the whole line text, checked before this scan, would avoid most of it.
Thanks for the thorough write-up. The marker-ownership rule fixes the composition races it describes, and the new cells in MarkerKeptByItsLine.test.ts fail on main and pass here. One regression needs fixing before merge; the rest are optional suggestions.
Must fix: pasting lines at the end of a line deletes that line's marker (packages/lexical-y/src/internal/Write.ts:4171-4191)
In the "line stays" branch of $markerContinues, a line whose text only grew at its end can claim only its own marker. An own marker, though, is kept only at the common prefix or suffix (withMarkerIslands takes record-placed markers only). So when one update adds text at the end of a line and a line after it, the old marker is deleted. That happens with RangeSelection.insertNodes of two paragraphs at the end of hello (the paste path), or with app code that sets hello! and inserts a paragraph after it. With two clients, in either client-id order:
main the line is held and the paste shows when the composition ends, as the Limits entry "Input method composition" in packages/lexical-website/docs/collaboration/y.md documents ("pasted lines ... wait until the composition ends, and the line keeps its nodes").helloA | B | next, where main gives helloA | Bnext.main applies it to the last pasted line.D118 says such a marker is kept "by that line itself", but no line keeps it. Falling back to position for a line that only grew at its end, with a new line after it (see the inline suggestion), restores main's result in each case. It keeps MarkerKeptByItsLine.test.ts, the regressions/ folder and the lane counts as they are on this branch. Please also add paste-at-end cells (packages/lexical-y/AGENTS.md, Testing: every fix lands with a regression test).
Suggestions (non-blocking)
MarkerKeptByItsLine.test.ts:164 and :213: on this branch the composed node ends detached ($blockOf returns −1), which .not.toBe(2) also accepts. With the n.isAttached() guard at :217, z is never typed, so "text typed as the composition ends stays in the code block" is not exercised. Pinning the expected index and asserting where the typed text lands (or retitling) would make the cells say what they check.packages/lexical-y/AGENTS.md (Decisions) asks that accepted limits also be documented in y.md's Limits. D118's limit (a replaced or remade line with a line added after it drops a concurrent attribute change) is not there yet, and the "Input method composition" entry still says the line keeps its nodes.Write.ts:4122-4134: endingWith scans every line that shares the last 8 characters. Remaking every line of a document whose lines end the same way takes about twice as long as on main (6,400 lines: about 2.0 s against 1.1 s; equal with distinct endings). An index keyed by the whole line text, checked before the suffix scan, would avoid it.main). AGENTS.md (Commits and Pull Requests) asks for the real Before and After output.<!-- codebunny-pub:1 k=37b1f0ba84fbd5499ae6b1932d891ccbffc7f02ad6c37eabf1afb4eb00fe0f9a -->
Must fix. This fallback covers only a line that grew at its end. A line that lost its end, with no new line ending with what it lost and a new line after it, still claims only its own marker (:4219), which can be kept only at the common prefix or suffix, so it is deleted. Selecting world in hello world and pressing Enter (RangeSelection.insertParagraph), or pasting two paragraphs over it (insertNodes), then drops a collaborator's concurrent center, heading change or Delete at the end of that line on every client, in both client-id orders; main keeps them on the new last line (hello / next for the Delete). The same happens on a document's last line and in a list item.
With a new line after the line, the suffix cannot reach its marker and the prefix reaches it only while the line's text is unchanged, so any changed line without a tail line needs the fallback. This keeps MarkerKeptByItsLine.test.ts and the whole packages/lexical-y unit project passing:
tails.length === 0 &&
head !== was &&
newLines.some((l, k) => l.isNew && k > own[own.length - 1])
Consider (non-blocking). This bullet lands inside the "Input method composition" entry: the paragraphs below it (:1324-1353, the held line's re-tokenization, NodeState and style caveats) belong to that entry but now render under "A line replaced next to a new line". Moving this bullet to just before "Set-valued NodeState" keeps them together.
Nit (non-blocking). On this branch A's saved node is detached once B's update arrives (MarkerKeptByItsLine.test.ts:165 pins −1), so there is no node to type at; what the test checks is that the text A composed stays in the quote. "Enter … store the same as before" also does not hold yet for Enter over a selection that reaches a line's end (see the comment in Write.ts).
Nit (non-blocking). Repeated, extended, on the next line.
Thanks for the quick turnaround on the last round: lines pasted at a line's end now keep main's result, remaking every line costs the same as main again, and the composition cells pin the detached node. The marker-ownership rule fixes the races it describes, and the new cells in MarkerKeptByItsLine.test.ts fail on main and pass here. One sibling of the paste-at-end case still needs fixing before merge; the rest are optional suggestions.
Must fix: Enter or a paste over a selection that reaches the end of a line deletes that line's marker (packages/lexical-y/src/internal/Write.ts:4220-4224)
The new position fallback applies only when the line grew at its end (n === was.length && head.length > was.length). A line that lost its end, with no new line ending with what it lost and a new line after it, still claims only its own marker, and that marker can be kept only at the common prefix or suffix. So selecting world in hello world and pressing Enter (RangeSelection.insertParagraph), or pasting two paragraphs over it (insertNodes), deletes the old marker. With two clients, gc on and off, in both client-id orders:
main applies it to the new empty line, or to the last pasted line);hello / empty line / next, where main gives hello / next;D118 says such a marker is kept "by that line itself", but no line keeps it, and the changeset's Verify: says Enter stores the same as before. Widening the condition fixes all of these (see the inline suggestion), and the whole packages/lexical-y unit project still passes with it. Please also add cells for Enter and a paste over a selection reaching the line's end beside the paste-at-end ones (packages/lexical-y/AGENTS.md, Testing: every bug fix lands with a regression test).
Suggestions (non-blocking)
packages/lexical-website/docs/collaboration/y.md:1319: the new "A line replaced next to a new line" bullet sits inside the "Input method composition" entry, so that entry's remaining paragraphs (:1324-1353, the held line's re-tokenization and NodeState caveats) now render under the new bullet. Moving it to just before "Set-valued NodeState" keeps them together..changeset/lexical-y-marker-kept-by-its-line.md:7: "text A types at the end of its saved node stays in the quote" describes a step this branch no longer allows, since that node is detached once B's update arrives; "the text A composed stays in the quote" is what the test checks.MarkerKeptByItsLine.test.ts:221: with the node pinned to −1 at :217, this guard always skips typing z, so "nothing typed lands there" holds with nothing typed.Write.ts:4119 repeats the comment on :4120.main). AGENTS.md (Commits and Pull Requests) asks for the real Before and After output.<!-- codebunny-pub:1 k=ba79b8f3c7a62e41d59fc9b564f72be5786ac583345c20ce106bb6b01cdd181d -->
Consider (non-blocking). With many identical lines remade in one update, this returns every one of them for each gone line, so each old marker gets a set of N lines and match (:4262-4272) walks it on every comparison. Replacing every paragraph with a new one of the same text takes about 6.9 s for 6,400 lines here against about 1.1 s on main (3,200: about 1.8 s against 0.7 s); distinct lines are unchanged. Claiming identical endings in order (a cursor per text, each gone line taking the next unclaimed line), or keeping position when more than one line ends with the text, keeps the set to one line; storing the claimed marker positions makes match a Set.has(j).
Consider (non-blocking). "next to it": with the block added before the replaced line (A composes at the end of see , B moves its children into a quote and inserts a code block before it), the composed node stays in the quote, as on main. Only a block added after it detaches the node, so "after it" is accurate.
Consider (non-blocking). This names a line replaced by "a new one holding the same text", but the concurrent change is also dropped when the replacement holds the line's own nodes and its text changes in the same update (the first reproducer's shape, where a transform changes the quote's text), and when app code splits a line without the record (hello world set to hello , then world and extra added; main centered extra). D118 covers the first; per packages/lexical-y/AGENTS.md (accepted limits in y.md, known failures as test.fails), consider widening this bullet and adding a cell for the app-code split next to MarkerKeptByItsLine.test.ts:311.
Thanks, this looks good. Keeping a line's marker with the line that continues it fixes the composition races the lanes reported, and the cases earlier revisions regressed (Enter or a paste over a line's end, lines pasted at a line's end, a split ending with an inline node, app-code splits) now give main's result, each with its own cells. Everything below is optional and non-blocking.
1. Remaking many identical lines is quadratic (packages/lexical-y/src/internal/Write.ts:4246, :4262-4272). For a line that is gone, endingWith(was) returns every line ending with its whole text, so with identical lines each old marker gets a set of all N lines and match walks it on every comparison. One update that replaces every paragraph with a new paragraph of the same text takes about 6.9 s for 6,400 lines here against about 1.1 s on main (3,200 lines: about 1.8 s against 0.7 s); distinct lines cost the same as before. Claiming identical endings in order (a cursor per text), or keeping position when more than one line ends with the text, keeps each set to one line; storing the claimed marker positions makes match a Set.has(j).
2. y.md's Limits bullet describes less than the code drops (packages/lexical-website/docs/collaboration/y.md:1349-1353). It names a line replaced by "a new one holding the same text". The concurrent alignment or type change is also dropped when the replacement holds the line's own nodes and its text changes in the same update (the shape of the first reproducer, where a transform changes the quote's text), and when app code splits a line without the record of text edits and adds another line after the tail (hello world set to hello , then world and extra added: main centered extra, this drops it). D118 covers the first. packages/lexical-y/AGENTS.md asks that accepted limits be documented in y.md and that known failures be test.fails cells, so consider widening the bullet and adding a cell for the app-code split next to MarkerKeptByItsLine.test.ts:311.
3. IME note wording (packages/lexical-website/docs/collaboration/y.md:1315-1318): "adds another block next to it". With the block added before the replaced line, the composed node stays in the quote, as on main; "after it" is accurate.
4. Test plan output: the pasted After run of MarkerKeptByItsLine.test.ts shows 72 cells, but the file now has 112 (104 passed, 8 expected fail). AGENTS.md (Commits and Pull Requests) asks for the real output of the command as run.
The composition cells run in jsdom; a collab-Y E2E or browser run of a real IME composition would be a useful follow-up, not a requirement for this change.
<!-- codebunny-pub:1 k=6167b286211bb7aa785cf009e3fc39cee44bf711f596850e93c3031ebe170f4b -->
Consider (non-blocking). This holds only where Lexical's record of text edits does not explain the replacement. When the collaborator moves the line's own nodes into the new block with their text unchanged (as $setBlocksType does) and then inserts a block after it, the line keeps its marker and the composed node stays held in the new block: the first cell of MarkerKeptByItsLine.test.ts without its upper-casing transform ends with the node in the quote and the code block untouched, on main and on this branch. Reusing the qualifier from the Limits bullet below ("holding the same text, or its own nodes with its text changed") would keep the two passages in agreement.
Consider (non-blocking). This is the only assertion in this cell that tells main from this branch (main gives 2): without it, the checks at lines 227-236 pass on main too, in all four cells, and nothing is typed after the composition ends, so the typed-text symptom in the comment above is not covered. Typing at A's selection once the composition ends and asserting which block holds the text would cover it.
Nit (non-blocking). CONTRIBUTING.md describes this entry as what people upgrading Lexical read. It might be worth one sentence on the accepted limit (D118, y.md Limits): in those shapes a collaborator's concurrent alignment or block-type change is now dropped, where before it landed on the added line.
This looks good to me. Keeping a line's marker with the line that continues it fixes the replaced-line race at its source, and the new cells in MarkerKeptByItsLine.test.ts fail on main and pass here, asserting both peers and a fresh reader in both client-id orders, with gc on and off. The accepted limit is recorded the way packages/lexical-y/AGENTS.md asks (a D118 row, y.md Limits, test.fails cells).
A few optional, non-blocking suggestions:
1. y.md composition paragraph (packages/lexical-website/docs/collaboration/y.md, lines 1315-1318): it says any replacement with a new block plus an added block gives the line a new marker and ends the composition. A plain block-type change (the line's own nodes moved into a quote with their text unchanged, then a block inserted after it) keeps the marker through Lexical's record of text edits, and the composed node stays held in the quote. Reusing the qualifier from the Limits bullet further down ("holding the same text, or its own nodes with its text changed") would keep the two passages in agreement.
2. Code-block composition cell (MarkerKeptByItsLine.test.ts, lines 192-238): only the $blockOf(key) check at line 218 tells main from this branch; the content assertions after it also pass on main, and nothing is typed after the composition ends, so the typed-text symptom the cell's comment mentions (lines 215-217) isn't covered. Typing at A's selection after the composition ends and asserting which block holds the text would cover it.
3. Changeset: CONTRIBUTING.md describes the changeset as the entry people upgrading Lexical read. One sentence on the accepted limit (in the D118 shapes, a collaborator's concurrent alignment or block-type change is now dropped, where it used to land on the added line) would tell them about that behaviour change alongside the fix.
4. Test plan: the pasted After output (104 passed | 8 expected fail (112), and "16 of the 112 cells fail" on main) predates the last test commits; the file now reports 104 passed | 24 expected fail (128), with 16 of 128 failing on main. AGENTS.md asks for the real output of the command that was run.
<!-- codebunny-pub:1 k=caacb01dd637c581fb4b64c75a1c49aab42c786c0cb434c36601057502488224 -->
Consider (non-blocking). This passes on main too, so it doesn't cover the typed-text symptom yet. On main, A's selection after B's update is the old see text node at offset 4 in the code block (the composed node, which moved to the paragraph, isn't selected), so z lands in the code block there as well; with the $blockOf check at line 218 removed, this cell passes on main in all four gc/id combinations. On both builds the text lands before what A composed (see zhttps://lexical.dev). Typing at the end of the composed node while it is still attached (on main it sits in the paragraph) would make this fail on main; otherwise the "(on main, the paragraph)" comment and the typed-text part of the title could go (packages/lexical-y/AGENTS.md, Testing).
Nit (non-blocking). A period is missing before "Accepted limit", so the accepted-limit text becomes part of the one-line summary. .changeset/README.md (Format) asks for a one-line [category] summary with further paragraphs after a blank line:
[fix] Keep a line's marker with the line that continues it: where a collaborator replaced a line (a change of its block type, or a new block holding its text) and added a block after it in one update, the new block took the old line's marker, so a client composing in that line saw its composition move to the new block, and ending it re-tokenized that block with its code highlighter (dropping its format and NodeState) or wrote what it typed there.
Accepted limit (DECISIONS.md D118, y.md Limits): where a collaborator replaces a line with a new block holding the same text (or its own nodes with their text changed), or splits it by app code, and adds another line after it in one update, another collaborator's concurrent change of that line's alignment or block type is now dropped (before, it landed on the added line).
Thanks, this looks good. Keeping a marker with the line that continues it fixes the replaced-line composition cases, the Enter, paste-at-end and Enter-over-a-selection cells give the same result as on main, and the accepted limit is recorded in D118, y.md's Limits and as test.fails cells, as packages/lexical-y/AGENTS.md asks. Run against main, the new MarkerKeptByItsLine.test.ts fails 16 of its 128 cells (the composition cells and the Backspace-with-a-line-added cells), and they pass here.
Two optional, non-blocking suggestions:
1. packages/lexical-y/src/__tests__/unit/regressions/MarkerKeptByItsLine.test.ts:219-240: the new z typing assertion also passes on main. After B's update, A's selection on main is the old see text node at offset 4 in the code block (not the composed node, which moved to the paragraph), so z lands in the code block there too, and on both builds it lands before the composed text (see zhttps://lexical.dev). With the $blockOf check at line 218 removed, the cell passes on main in all four gc/id combinations. packages/lexical-y/AGENTS.md (Testing) asks for a control on the baseline a claim names: typing at the end of the composed node while it is still attached would make this assertion fail on main; otherwise the "(on main, the paragraph)" comment and the typed-text part of the test title could go.
2. .changeset/lexical-y-marker-kept-by-its-line.md:5: there is no period between "typed there" and "Accepted limit", so the accepted-limit text becomes part of the one-line summary. .changeset/README.md (Format) asks for a one-line [category] summary with further paragraphs after a blank line; ending the summary at "there." and moving the accepted limit into its own paragraph keeps the changelog entry readable.
<!-- codebunny-pub:1 k=2af27ee8f628a834a56dc68599f09add68b7255f7c9a4e48c8925d0cc657ed87 -->
Nit (optional). As written ("a quote holding its text"), this check also passes on main when the quote holds the paragraph's own nodes unchanged, as $setBlocksType leaves them: the first cell of MarkerKeptByItsLine.test.ts without its upper-casing transform passes on both builds. Naming the shape that differs would make the check tell them apart, and match y.md's qualifier:
Verify: with two clients, A composes at the end of a paragraph while B replaces that paragraph with a quote whose text changes in the same update (a transform that upper-cases it, or new text nodes holding the same text) and adds a code block with underlined text after it; when A's composition ends, the code block keeps its underline and NodeState on every client, and the text A composed stays in the quote. Enter, Backspace across lines and a range delete across lines store the same as before.
This looks good to me. Keeping an old line marker with the line that continues it (D118) fixes the replaced-line case, and the "as before" cells show that pastes and Enter over a line's end keep main's results. The new regression cells fail on main and pass here, including the case where the untouched code block is re-tokenized and loses its underline. The accepted limit is recorded in DECISIONS.md, y.md's Limits and the test.fails cells, as packages/lexical-y/AGENTS.md asks.
All suggestions below are optional and non-blocking:
Verify: recipe (.changeset/lexical-y-marker-kept-by-its-line.md:9). As written ("a quote holding its text"), the check also passes on main when the quote holds the paragraph's own nodes unchanged, as $setBlocksType leaves them. The first cell in MarkerKeptByItsLine.test.ts without its upper-casing transform passes on both. .changeset/README.md ("Behavior changes") says Verify: should name what to test for the change, so it could say the quote's text changes in the same update (or new text nodes hold it), matching the qualifier y.md already uses.$setCompositionKey. If it's easy, a collab-Y browser or e2e check of that shape (pnpm run test-e2e-collab-y-chromium) would cover how a real input method reacts.carry:target-value ceiling (LaneFuzz.test.ts:174). Raising it from 7.2 to 9.8 per 1,000 loosens the nightly growth check for that class. Keeping it in its own commit, as you did, leaves maintainers free to take or drop it.<!-- codebunny-pub:1 k=a34ca35693335839b813de3d202d7a01e4fe40e43b99ae3f486d86609743adf3 -->
This looks good to me. The new rule is clearly recorded (D118, y.md's Limits and the changeset), the composition and join cells in MarkerKeptByItsLine.test.ts fail on main and pass here, and the rest of the @lexical/y unit suite passes with gc off and on. Other concurrent shapes produce the same documents as on main, each against a concurrent alignment change or typing: moving lines, mid-line and cross-line pastes, Enter over a multi-line selection, a paragraph made a heading with a line added before or after it, removals and joins.
Two optional, non-blocking notes:
1. packages/lexical-y/src/__tests__/unit/LaneFuzz.test.ts:172: carry:target-value is the one known-open class this change makes more frequent (7.2 → 9.8 per 1,000). The explanation reads right: these histories now take the join path, which fails the same way on main without the added block. An issue for that join-path failure would give the raised ceiling an owner, so the last commit can be kept or dropped knowingly.
2. packages/lexical-y/src/__tests__/unit/regressions/MarkerKeptByItsLine.test.ts:217: as discussed on this line before, the $blockOf check is still the only assertion in the code-block cell that fails on main, so the typed-text symptom of that history has no cell of its own yet (packages/lexical-y/AGENTS.md, Testing). Fine as a follow-up.
<!-- codebunny-pub:1 k=a79ca56b75837267f1b354712cbb05efc0ce69ace4d45e44130328863f7c5cf8 -->
Consider (non-blocking). One concurrent shape next to these isn't pinned, and its stored outcome changes with this PR. When A joins or splits a line and adds a line after it, and B concurrently joins the next line into it, the joined line now absorbs A's added line. From one / two / three / four, A presses Backspace at the start of two and adds added after onetwo, while B presses Backspace at the start of three. main gives onetwo / addedthree / four; this branch gives onetwoadded / three / four (gc off and on, both id orders, converged). The same happens with Enter, a range delete or a removed line in place of A's join or B's Backspace. It follows from D118 (the joined line keeps the marker after two, which B deletes), so a cell here pinning it would make a later change deliberate (packages/lexical-y/AGENTS.md, Testing).
Consider (non-blocking). This scan runs once per staying line. In my timings, edits that touch every line of a 6,000-line document took 8-21% longer than on main (for example 799 to 963 ms to append to every line and add a line after each), growing linearly. Typing returns at the first check above, so only bulk edits pay. If it matters, computing the index of the last new line once, before the loop, would turn this into a comparison.
This looks good to me. The rule is clearly recorded (D118, y.md's Limits and the changeset). The composition and Backspace-join cells in MarkerKeptByItsLine.test.ts fail on main and pass here with gc off and on, and the quote cell reproduces the user-visible symptom (the untouched code block keeps text:8:old instead of being re-tokenized). I also tried other concurrent shapes against a collaborator centering a line, making it a heading or typing at its end: moves, mid-line pastes, Enter, $setBlocksType with a line added after, removals and range deletes all converge. They either match main or now keep the change on the line that continues the old one. The carry:target-value increase is reasonable now that #9865 tracks the join-path failure.
Three optional, non-blocking suggestions:
1. Pin the concurrent-join outcome (MarkerKeptByItsLine.test.ts, next to the concurrent-delete cells at line 528). When A joins or splits a line and adds a line after it, and B concurrently joins the next line into it, the joined line now absorbs A's added line. For example, from one / two / three / four, A presses Backspace at the start of two and adds added, while B presses Backspace at the start of three. main gives onetwo / addedthree / four; this branch gives onetwoadded / three / four, in both client-id orders and with gc on and off. It follows from D118, and neither result is ideal, but the stored outcome changes in a shape no cell covers. packages/lexical-y/AGENTS.md (Testing) asks to test the input space, and one cell would make a later change here deliberate.
2. The code-block composition cell (MarkerKeptByItsLine.test.ts:217): as noted on that line before, the $blockOf check is still the only assertion in it that fails on main. With it removed, all four cells pass on main, and the text typed after the composition lands in the code block on both. So the "wrote what it typed there" symptom in the changeset has no failing-first cell yet (packages/lexical-y/AGENTS.md, Testing: every bug fix lands with a regression test). Fine as a follow-up.
3. Whole-document writes (packages/lexical-y/src/internal/Write.ts:4223): in my timings, edits that touch every line of a 6,000-line document (reversing the lines, appending to each line and adding a line after it, removing every other line, replacing each line) took 8-21% longer than on main, growing linearly. Typing and single-line edits return at the first check of $markerContinues, so this only matters for bulk edits. If you want it back, the newLines.some(...) scan here runs once per staying line and could use a precomputed index of the last new line.
<!-- codebunny-pub:1 k=9c152cd2eec05217ab2472761b8931ed50bafdaf700c712ca1baa4240d191d5c -->
Nit (optional). In this recipe's cell on main (MarkerKeptByItsLine.test.ts:140-190), the code block comes back as code-highlight nodes with format 0 and note still old on every peer, as the description's Before output also shows ("note":"old" on both sides). Only the formats are dropped, so naming those tells upgraders what they will see (CONTRIBUTING.md, Changesets):
[fix] Keep a line's marker with the line that continues it: where a collaborator replaced a line (a change of its block type, or a new block holding its text) and added a block after it in one update, the new block took the old line's marker, so a client composing in that line saw its composition move to the new block, and ending it re-tokenized that block with its code highlighter (dropping its formats, such as underline) or wrote what it typed there.
Thanks, this looks good. Keeping a line's marker with the line that holds its end fixes the replaced-line race cleanly: the composition and join cells in MarkerKeptByItsLine.test.ts fail on main and pass here, and the cells for Enter, pastes at or over a line's end and app-code splits end the same on both. The accepted limit (DECISIONS.md D118, y.md Limits, the three test.fails) and the pinned concurrent-join outcome read as deliberate, so nothing below blocks.
Optional, non-blocking:
1. Changeset summary (.changeset/lexical-y-marker-kept-by-its-line.md:5): it says ending the composition re-tokenized the block "(dropping its format and NodeState)". In the Verify: recipe's cell on main, the code block's re-tokenized nodes keep note: 'old' and lose only their underline, which matches the "note":"old" on both sides of the Before output in the description. CONTRIBUTING.md (Changesets) says this entry is what people upgrading read, so "(dropping its formats, such as underline)" would be more accurate.
2. Test plan counts: the After block reports 104 passed | 24 expected fail (128) and 16 cells failing on main. With the typed-text and concurrent-join cells added since, the file now runs 112 passed | 24 expected fail (136), and 24 cells fail on main. AGENTS.md (Commits and Pull Requests) asks the Test plan to carry the real output of the command, so pasting the current run would keep it accurate.
<!-- codebunny-pub:1 k=393dd09a08f7d044356dea2d132b286a37105459567d0592d19aad7d949556ce -->
Nit (optional). Two of these rules lag the code: a line that stays gives its marker to any line by position when a new line follows it and no line holds its old end (:4228), and a gone line's text claims only where exactly one line ends with it (:4255). D118 already states both; this keeps the invariant comment in step:
* - where the old line stays: a new line after it ending with what it
* lost from its end (a split the record does not explain: app code that
* sets the head's text and adds a line holding the tail); else, where a
* new line follows it, any line by position as before (lines pasted at
* its end, Enter or a paste over a selection that reaches its end); else
* that line itself;
* - where it is gone: the lines holding a node it held before this update
* (a line Lexical replaced, `$setBlocksType`, or one joined into another),
* else the one line ending with all of its text (a paste over it; with
* several, by position);
Thanks, this looks good. Keeping a line's marker with the line that continues it fixes the replaced-line race cleanly: the composition, join and typed-text cells in MarkerKeptByItsLine.test.ts fail on main and pass here, and the cells for Enter, pastes at or over a line's end and app-code splits end the same on both. The accepted limit (DECISIONS.md D118, y.md Limits, the three test.fails) and the pinned concurrent-join outcome read as deliberate, and the changeset now names the formats main lost.
Optional, non-blocking:
1. Test plan, Before: the MarkerKeptByItsLine.test.ts run on main is summarised in parentheses rather than pasted. AGENTS.md (Commits and Pull Requests) asks for the real output ("Paste real output — do not describe it"); vitest's Tests 24 failed | 112 passed (136) line for that run would do.
2. $markerContinues JSDoc (packages/lexical-y/src/internal/Write.ts:3999-4005): it says a line that stays keeps its marker, and that a gone line's marker goes to "the lines ending with all of its text". The code gives a staying line's marker to any line by position when a new line follows it and no line holds its old end (:4228), and lets a gone line's text claim only where exactly one line ends with it (:4255). D118 already states both rules; aligning the comment keeps the function's invariant accurate for the next reader (suggestion inline).
<!-- codebunny-pub:1 k=72ec135242baeb8b5a3ced5c36e2e9c574cfd695a6e32b6379d05841aa5bc211 -->
Consider (non-blocking). In these shapes the old marker is deleted, so a collaborator's concurrent Delete at the end of the line (or Backspace at the start of the next) is dropped too, not just an alignment or block-type change. Start from intro / see / next. A moves see's nodes into a quote, sets its text to SEE and adds xyz after it, while B presses Delete at the end of see. main gives intro / SEE / xyznext; this branch gives intro / SEE / xyz / next (gc off and on, both id orders, converged). The same holds for a line remade with the same text and for an app-code split with an extra line. No text is lost, and main joined the wrong line, but this bullet, D118 and the changeset's accepted-limit paragraph describe only alignment and block type. Per packages/lexical-y/AGENTS.md (accepted limits in y.md's Limits, known failures as test.fails), consider adding "or a Delete that joins the next line into it" here, and a test.fails cell beside MarkerKeptByItsLine.test.ts:360.
Consider (non-blocking). The split half of "a join or split with a line added after it" has no cell: the join is pinned here, and the Enter cell at :301 adds no line. This cell passes on this branch and fails on main, where the change lands on added, for both changes, both id orders and both gc settings:
test('Enter in a line, with a line added after the tail: the tail keeps the change', () =>
run(
() =>
$getRoot().append(
$createParagraphNode().append($createTextNode('hello world')),
),
() => {
$selectIn([0], 6).insertParagraph();
($getRoot().getChildAtIndex(1) as ElementNode).insertAfter(
$createParagraphNode().append($createTextNode('added')),
);
$setSelection(null);
},
0,
['paragraph:hello ', changed('paragraph', 'world'), 'paragraph:added'],
));
Consider (non-blocking). The split counterpart of this outcome isn't pinned. From hello world / next, A runs $selectIn([0], 6).insertParagraph() and adds added after the tail, while B runs $selectIn([0], 11).deleteCharacter(false). Every peer and a fresh reader end at ['hello ', 'worldadded', 'next']; main gives ['hello ', 'world', 'addednext'] (gc off and on, both id orders). It follows from D118 in the same way: the tail keeps the marker B's Delete removes. A twin of this cell would make a later change to the split path deliberate too.
Thanks, this looks good to me. Keeping an old line marker only with the line that continues it fixes the composition and concurrent-alignment cases the description lists. The new cells in MarkerKeptByItsLine.test.ts fail on main and pass here, and the accepted limit is recorded in D118, y.md's Limits and the changeset, as packages/lexical-y/AGENTS.md asks.
A few optional, non-blocking suggestions:
1. The accepted limit also drops a concurrent join (packages/lexical-website/docs/collaboration/y.md:1350). Start from intro / see / next. A moves see's nodes into a quote, changes its text to SEE and adds xyz after it, while B presses Delete at the end of see. main gives SEE / xyznext; this branch gives SEE / xyz / next, so B's Delete has no effect. The same happens for a line remade with the same text, with Backspace at the start of the next line, and for an app-code split with an extra line. No text is lost, but the y.md bullet, D118 and the changeset mention only alignment and block type. packages/lexical-y/AGENTS.md puts accepted limits in y.md's Limits and known failures in test.fails, so consider naming the dropped join there and adding a test.fails cell next to the existing ones.
2. Pin the split with a line added after the tail (MarkerKeptByItsLine.test.ts:447). Press Enter after hello in hello world and add a paragraph after the tail: here a concurrent center or h2 stays on world, while on main it goes to the added paragraph. No cell covers this; only the join is pinned. packages/lexical-y/AGENTS.md asks every fix to land with a regression test in regressions/, and the inline comment has a cell that fails on main and passes here.
3. Pin the split counterpart of the concurrent-join outcome (MarkerKeptByItsLine.test.ts:863). With that same split and added line, B's Delete at the end of hello world now gives hello / worldadded / next (main: hello / world / addednext). This is the same "neither keeps both intents" class as the join cell, so a twin cell there would make a later change deliberate.
<!-- codebunny-pub:1 k=13bdfd2bdbe4cb776b2a7af4036d66324c4a342927ff0ebb8cf67d19446c905c -->
Thanks, this looks good to me. Keeping an old line marker only with the line that continues it fixes the composition and concurrent-alignment cases in the description. At this head, 32 cells in MarkerKeptByItsLine.test.ts fail on main and pass here, and the @lexical/y unit tests pass with gc off and on. The accepted limit is recorded in D118, y.md's Limits, the changeset and test.fails cells, as packages/lexical-y/AGENTS.md asks for an accepted limit.
Two optional, non-blocking suggestions:
1. Refresh the Before output in the Test plan. It still shows 24 failed | 88 passed | 24 expected fail (136) for MarkerKeptByItsLine.test.ts on main. At this head the file has 148 cells, and main gives 32 failed | 88 passed | 28 expected fail (148). AGENTS.md (Commits and Pull Requests) asks the Test plan for the real output of the command that was run.
2. Consider a collab-y e2e check of the replaced-line composition (packages/lexical-website/docs/collaboration/y.md:1315-1319). The composition cells set the composition key with $setCompositionKey in jsdom. They show that the held node leaves the document, but not what a real input method does with characters composed after the collaborator's replacement arrives; y.md says only that the composition "ends without it". A spec under packages/lexical-playground/__tests__/e2e/ (run with pnpm run test-e2e-collab-y-chromium) would show where that input goes. In it, one client composes at the end of a line while the other moves the line's nodes into a quote, changes their text and adds a block after it. AGENTS.md (Testing Strategy) sends behaviour that needs a real browser's selection engine to the browser or e2e tiers rather than jsdom.
<!-- codebunny-pub:1 k=bdd81da53e9b61e03509b362e82e813909a63c3698d79a5a6877a84220b76bea -->
Approved these changes.
potatowagon
zurfyx
Description
$writeSeqmatched a line marker to any marker: only the kind was compared (matchSpecial). Where a collaborator replaced a line (a change of its block type, or a new block of the same type holding its text) and added a block after it in the same update, the common suffix gave the old line's marker to the new block, and the replacement got a new marker. Every reader keys a line by its marker, so on a client composing in that line the composed text node, and the line held while composing, moved to the new block. Ending the composition then re-tokenized a collaborator's untouched code block with the composer's highlighter (dropping its formats, such as underline), or wrote the text the composer typed into the block after the line.Where a write holds more than one marker on either side, an old marker is now kept only by the line that continues the line it ended (
$markerContinues, DECISIONS.md D118), the first of:1. the line whose last atom (a character, or an inline node kept) is the old line's last atom, by Lexical's record of text edits: the tail of a split, or the line a join or a range delete across lines ends with the joined text;
2. where the old line stays: the one new line after it ending with what it lost from its end (a split the record does not explain); else, where a new line follows it, by position as before (lines pasted at its end, Enter or a paste over a selection reaching its end: the last new line keeps it); else that line itself;
3. where it is gone: a line holding a node it held (a line Lexical replaced,
$setBlocksType, or one joined into another), else the one line ending with all of its text (with several, by position);4. where no line continues it: any line, by position, as before.
A marker the record places is also kept between the common prefix and suffix (
withMarkerIslands), so a join or split with a line added after it keeps it; any other marker is kept only at the common prefix or suffix, as before (kept elsewhere, a concurrent join on another client may delete it and leave the line without a boundary). Split: the line holding the tail keeps the marker and the head gets a new one. Join: the line before keeps the marker after the joined text. No character moves for a marker. The attribute repair for a marker another line had ($markerBefore) stays: a split, a join and a replacement still give a line a marker it did not own.Accepted limit (D118, y.md Limits,
test.fails): a line replaced by a new block (holding the same text, or its own nodes with its text changed), or split by app code without the record of text edits, with another line added after it in the same update, gets a new marker, so another collaborator's concurrent change of that line's alignment or block type, or a Delete at its end, is dropped (before, it was applied to the added line). No text is lost.Stored bytes change only where a line continues the old line and
maingave the marker to another one. Over the fuzz seeds and 100 random sessions per gc setting (294 paired sessions), every update and state equalsmain's; Jot's stored notes (40 per gc) hash equal.Lanes (13,000 histories per lane and gc, per 1,000,
main→ this): blockconv ending-phase-other-block 26.5 → 4.2, untouched-block-changed 26.3 → 2.5, ending-phase-text 8.6 → 5.4, ending-phase-code-highlight-outside-code 9.2 → 6.3, ending-phase-boundary 0.1 → 0; carry ending-phase-code-highlight-outside-code 196.5 → 8.5, ending-phase-field 187.3 → 4.6, and decorator-lost, ending-phase-text, other-block-changed, ending-phase-other-block, ending-phase-state → 0.KNOWN_OPENis updated accordingly.Pinned outcome changes (cells): A joins a line into the one before and adds a line after it while B joins the next line into the joined one:
onetwoadded/three/four(main:onetwo/addedthree/four); likewise for Enter mid-line with a line added after the tail while B deletes at the line's end (hello/worldadded/next;main:hello/world/addednext). Neither keeps both intents.One class grows:
carry:target-value, 7.2 → 9.8. All 71 histories that show it only with this fix are a collaborator joining the held code line into the paragraph before it and adding a block after it; onmainthe marker went to that added block, and 70 of them showed other findings there (68decorator-lost). Replayed without the added block, all 71 fail identically onmainand with this fix. The last commit records the new rate on its own, to take or drop; the join-path failure is tracked in #9865.Test plan
Before
The 32 failures: the composed node moves into the added block, text typed at it lands there, a joined or split line's concurrent change lands on the added line, and a concurrent join of the next line lands on the added line. The 28 expected failures are the accepted limit's cells, which fail on
maintoo.The two histories are reproduced as cells in
MarkerKeptByItsLine.test.ts(gc off and on, both orders of the collaborators' ids), with a split ending with an inline node, app-code splits, a join with a line added after it, lines removed while a collaborator types in one, concurrent deletes across lines with a replaced line, lines pasted at the end of a line, and Enter or a paste over a selection reaching a line's end.After
Both histories pass strict replay at gc off and on with client ids [11,22], [22,11], [44,55] and [55,44] (and the boundary history 106259, which fails on
main). The gate of record (gate20k, kf2k, invns2k) is 0 worse thanmain; no-hold 0 of 40,000 differ. A rewrite of every line of a 3,200-line container takes about 250 ms (mainabout 350 ms); remaking every line of a 6,400-line document whose lines share a long ending, or are identical, takes about the same time as onmain.