← Back to Pull requests

[lexical-y] Bug Fix: Keep a remote read's commit from running node transforms when its text merges under the caret #9779

Merged
zurfyx merged 3 files (218 lines) on Nov 04, 2026 08:26 UTC
View on GitHub
zurfyx zurfyx commented on Nov 04, 2026 05:52 UTC
Author

Description

Every read of a remote change into the editor runs without node transforms,
and at its end the binding counts the read's selection as notified
($quietSelection), so that Lexical does not extend the read's commit with
SELECTION_CHANGE_COMMAND (an extension runs every node transform over the
update's changes, whatever the update's options).

The binding counted a copy of the selection. A read can leave two text nodes
side by side that Lexical's normalization merges at the end of the update
(they differ only in what the binding stores for them, such as their
segment), and the caret can be in the second one. The merge moves the
caret's points in place onto the merged node, so at commit the selection no
longer equalled the copy: Lexical extended the read's commit and ran the
transforms. With the code highlighter registered, a code highlight outside a
code block became plain text in that editor only. The commit is a read, so
the binding neither wrote that change nor read the content again: the editor
kept showing plain text while the document, every other client and a fresh
read showed the code highlight.

The binding now counts the selection itself as notified, so the commit
compares it with what the normalization leaves of it. Lexical gives each
later update a selection of its own, so the stored one does not change
after the read commits. Selection listeners still hear of the change from
the update the binding dispatches SELECTION_CHANGE_COMMAND in after the
read.

Found by randomized collaborative sessions (an author's undo read in a quote holding code
text typed concurrently); the cell reproduces it with two clients and an
outside writer.

Test plan

Before

ReadMergedUnderCaret.test.ts: A (no highlighter) stores a code highlight
outside code; B has a root element, the highlighter, and its caret in the
text next to it. An outside writer gives part of the text a segment of its
own and A removes the text B's caret is in.

AssertionError: expected 'paragraph(text:"one two y three")' to be 'paragraph(text:"one two" code-highlig…' // Object.is equality
 Test Files  1 failed (1)
      Tests  4 failed | 2 passed (6)

After

 ✓ |unit| packages/lexical-y/src/__tests__/unit/regressions/ReadMergedUnderCaret.test.ts (6 tests)
 ✓ |unit| packages/lexical-y/src/__tests__/unit/ReadSelection.test.ts (2 tests)
 ✓ |unit| packages/lexical-y/src/__tests__/unit/Focus.test.ts (7 tests)

Units, LEXICAL_Y_GC=0 and =1 (vitest run --project unit packages/lexical-y):

 Test Files  267 passed | 2 skipped (269)
      Tests  19706 passed | 379 expected fail | 131 skipped (20216)
 Test Files  267 passed | 2 skipped (269)
      Tests  19703 passed | 382 expected fail | 131 skipped (20216)

pnpm run ci-check passes (Found 0 errors); check-changesets passes.

Unchanged by this PR (same on main)

A read can still run node transforms when a TextNode's selectionTransform replaces the read's selection after the binding counted it (with a new range, a node selection or null), or changes it in place when the read left the selection equal to the notified one. Both happen on main too; this PR fixes the case where Lexical's own merge moves the caret.

Diff: 218 lines (+216 / -2) across 3 files Reviewer: zurfyx Review duration: 154m
All Vouch review confidence checks passed
Residual risk 0.09 = Change Risk (0.52) × (1 − Review Confidence (0.83)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 218 lines diff across 3 files
0.52
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.89 · 5 substantive comment(s)
0.89
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
83%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.322
Self Review self_review
0.140
Real PR Conversation Timeline
8 items
vercel[bot] vercel[bot] commented on Nov 04, 2026 05:52 UTC
Bot

[vc]: #oDooFyKLO5vhSXF5MGA2EbKuV5byb2o4a3rvsgUnxpA=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJsZXhpY2FsIiwicHJvamVjdElkIjoicHJqX01SYU1PMzFlRklrWTYxU0JxcVBEUjJPank4cVAiLCJ2MCI6ZmFsc2UsInJvb3REaXJlY3RvcnkiOiJwYWNrYWdlcy9sZXhpY2FsLXdlYnNpdGUiLCJpbnNwZWN0b3JVcmwiOiJodHRwczovL3ZlcmNlbC5jb20vZmJvcGVuc291cmNlL2xleGljYWwvRUQxZnQ0YXN0MUY1aFVpVlBRSzNWS2I2dGh3UCIsInByZXZpZXdVcmwiOiJsZXhpY2FsLWdpdC16dXJmeXgteS1xdWlldC1zZWxlY3Rpb24tc2FtZS1vYmplY3QtZmJvcGVuc291cmNlLnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiREVQTE9ZRUQifSx7Im5hbWUiOiJsZXhpY2FsLXBsYXlncm91bmQiLCJwcm9qZWN0SWQiOiJwcmpfZWE4MnZMajY4NFh6U1JkZU83SlNkMFFOa2F3cyIsInYwIjpmYWxzZSwicm9vdERpcmVjdG9yeSI6InBhY2thZ2VzL2xleGljYWwtcGxheWdyb3VuZCIsImluc3BlY3RvclVybCI6Imh0dHBzOi8vdmVyY2VsLmNvbS9mYm9wZW5zb3VyY2UvbGV4aWNhbC1wbGF5Z3JvdW5kLzJHOFU2YlBOS3k4TGpTZlpjRW01dGkxd2hzQVIiLCJwcmV2aWV3VXJsIjoibGV4aWNhbC1wbGF5Z3JvdW5kLWdpdC16dXJmeXgteS1xdWlldC1zZWxlYy1lZjZiMjItZmJvcGVuc291cmNlLnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiREVQTE9ZRUQifV0sInJlcXVlc3RSZXZpZXdVcmwiOiJodHRwczovL3ZlcmNlbC5jb20vdmVyY2VsLWFnZW50L3JlcXVlc3QtcmV2aWV3P293bmVyPW1ldGEmcmVwbz1sZXhpY2FsJnByPTk3NzkifQ==
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-04T06:08:21.568Z">Nov 4, 2026 6:08am 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-04T06:08:21.568Z">Nov 4, 2026 6:08am UTC</relative-time> |

<a href="https://vercel.com/vercel-agent/request-review?owner=meta&repo=lexical&pr=9779" 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>

meta-code-review[bot] meta-code-review[bot] commented on Nov 04, 2026 05:52 UTC
Bot

AI review status for this pull request.

| Review status | Updated |
| :--- | :--- |
| 🟢 Reviewed (for maintainers only) | <relative-time datetime="2026-11-04T06:25:46Z">Nov 4, 2026, 6:25 AM UTC</relative-time> |

<!-- codebunny-status:1 r=318341089 p=9779 rv=2 -->

pkg-pr-new[bot] pkg-pr-new[bot] commented on Nov 04, 2026 05:55 UTC
Bot

<details><summary><b>lexical</b></summary><p>

  npm i https://pkg.pr.new/lexical@9779
  


</p></details>

<details><summary><b>@lexical/a11y</b></summary><p>

  npm i https://pkg.pr.new/@lexical/a11y@9779
  


</p></details>

<details><summary><b>@lexical/clipboard</b></summary><p>

  npm i https://pkg.pr.new/@lexical/clipboard@9779
  


</p></details>

<details><summary><b>@lexical/code</b></summary><p>

  npm i https://pkg.pr.new/@lexical/code@9779
  


</p></details>

<details><summary><b>@lexical/code-core</b></summary><p>

  npm i https://pkg.pr.new/@lexical/code-core@9779
  


</p></details>

<details><summary><b>@lexical/code-prism</b></summary><p>

  npm i https://pkg.pr.new/@lexical/code-prism@9779
  


</p></details>

<details><summary><b>@lexical/code-shiki</b></summary><p>

  npm i https://pkg.pr.new/@lexical/code-shiki@9779
  


</p></details>

<details><summary><b>@lexical/compiler</b></summary><p>

  npm i https://pkg.pr.new/@lexical/compiler@9779
  


</p></details>

<details><summary><b>@lexical/devtools-core</b></summary><p>

  npm i https://pkg.pr.new/@lexical/devtools-core@9779
  


</p></details>

<details><summary><b>@lexical/dragon</b></summary><p>

  npm i https://pkg.pr.new/@lexical/dragon@9779
  


</p></details>

<details><summary><b>@lexical/eslint-plugin</b></summary><p>

  npm i https://pkg.pr.new/@lexical/eslint-plugin@9779
  


</p></details>

<details><summary><b>@lexical/extension</b></summary><p>

  npm i https://pkg.pr.new/@lexical/extension@9779
  


</p></details>

<details><summary><b>@lexical/fast-check</b></summary><p>

  npm i https://pkg.pr.new/@lexical/fast-check@9779
  


</p></details>

<details><summary><b>@lexical/file</b></summary><p>

  npm i https://pkg.pr.new/@lexical/file@9779
  


</p></details>

<details><summary><b>@lexical/hashtag</b></summary><p>

  npm i https://pkg.pr.new/@lexical/hashtag@9779
  


</p></details>

<details><summary><b>@lexical/headless</b></summary><p>

  npm i https://pkg.pr.new/@lexical/headless@9779
  


</p></details>

<details><summary><b>@lexical/history</b></summary><p>

  npm i https://pkg.pr.new/@lexical/history@9779
  


</p></details>

<details><summary><b>@lexical/html</b></summary><p>

  npm i https://pkg.pr.new/@lexical/html@9779
  


</p></details>

<details><summary><b>@lexical/internal</b></summary><p>

  npm i https://pkg.pr.new/@lexical/internal@9779
  


</p></details>

<details><summary><b>@lexical/link</b></summary><p>

  npm i https://pkg.pr.new/@lexical/link@9779
  


</p></details>

<details><summary><b>@lexical/list</b></summary><p>

  npm i https://pkg.pr.new/@lexical/list@9779
  


</p></details>

<details><summary><b>@lexical/mark</b></summary><p>

  npm i https://pkg.pr.new/@lexical/mark@9779
  


</p></details>

<details><summary><b>@lexical/markdown</b></summary><p>

  npm i https://pkg.pr.new/@lexical/markdown@9779
  


</p></details>

<details><summary><b>@lexical/mdast</b></summary><p>

  npm i https://pkg.pr.new/@lexical/mdast@9779
  


</p></details>

<details><summary><b>@lexical/offset</b></summary><p>

  npm i https://pkg.pr.new/@lexical/offset@9779
  


</p></details>

<details><summary><b>@lexical/overflow</b></summary><p>

  npm i https://pkg.pr.new/@lexical/overflow@9779
  


</p></details>

<details><summary><b>@lexical/plain-text</b></summary><p>

  npm i https://pkg.pr.new/@lexical/plain-text@9779
  


</p></details>

<details><summary><b>@lexical/react</b></summary><p>

  npm i https://pkg.pr.new/@lexical/react@9779
  


</p></details>

<details><summary><b>@lexical/rich-text</b></summary><p>

  npm i https://pkg.pr.new/@lexical/rich-text@9779
  


</p></details>

<details><summary><b>@lexical/selection</b></summary><p>

  npm i https://pkg.pr.new/@lexical/selection@9779
  


</p></details>

<details><summary><b>@lexical/table</b></summary><p>

  npm i https://pkg.pr.new/@lexical/table@9779
  


</p></details>

<details><summary><b>@lexical/tailwind</b></summary><p>

  npm i https://pkg.pr.new/@lexical/tailwind@9779
  


</p></details>

<details><summary><b>@lexical/text</b></summary><p>

  npm i https://pkg.pr.new/@lexical/text@9779
  


</p></details>

<details><summary><b>@lexical/utils</b></summary><p>

  npm i https://pkg.pr.new/@lexical/utils@9779
  


</p></details>

<details><summary><b>@lexical/y</b></summary><p>

  npm i https://pkg.pr.new/@lexical/y@9779
  


</p></details>

<details><summary><b>@lexical/yjs</b></summary><p>

  npm i https://pkg.pr.new/@lexical/yjs@9779
  


</p></details>

_commit: <a href="https://github.com/meta/lexical/runs/126420933844"><code>7660f65</code></a>_

meta-code-review[bot] meta-code-review[bot] commented on code on Nov 04, 2026 06:06 UTC
Code Review
.changeset/lexical-y-read-merged-under-caret.md:1
@@ -0,0 +1,7 @@
+---
+'@lexical/y': patch
+---
+
+[fix] A remote change read into an editor with a root element runs no node transforms when the text it leaves merges under the caret, so the editor keeps showing what the document stores
+
+A read can leave two text nodes side by side that Lexical merges at the end of the update (they differ only in what the binding stores for them), and the caret can be in the second one. The merge moved the caret after the binding had counted the read's selection as notified, so Lexical extended the read's commit with the selection change command and ran every node transform over what the read brought: a code highlight outside a code block, for one, became plain text in that editor only, and stayed so, while every other client and a fresh read of the document showed the code highlight. The read's selection now counts as notified as the merge leaves it.

Optional, non-blocking: consider adding a Verify: paragraph after this one. CONTRIBUTING.md (Changesets) and .changeset/README.md (Behavior changes) ask for one when a fix changes observable editing behavior. For example:

Verify: with the code highlighter registered, have a collaborator's change leave the caret in text that Lexical merges, and check that a code highlight outside a code block stays a code highlight and the editor equals a fresh read of its document.

meta-code-review[bot] meta-code-review[bot] approved these changes on Nov 04, 2026 06:06 UTC
Approved Reviewer

This looks good to me. $quietSelection (packages/lexical-y/src/internal/Binding.ts) now stores the read's selection itself rather than a copy. That closes the gap where the text merge at the end of the update moved the caret after the copy was taken. The reasoning that the stored object cannot change after the commit also holds: committed selections are frozen in development, and every later update builds its own selection. The new regression test reproduces the race with two clients and an outside writer, fails without the fix, and checks the editor against a fresh read of its document.

Optional, non-blocking:

  • .changeset/lexical-y-read-merged-under-caret.md: consider adding a Verify: paragraph. CONTRIBUTING.md (Changesets) and .changeset/README.md (Behavior changes) ask for one when a fix changes observable editing behavior, and it lists the entry under "Behavior changes" in the changelog. For example: Verify: with the code highlighter registered, have a collaborator's change leave the caret in text that Lexical merges, and check that a code highlight outside a code block stays a code highlight and the editor equals a fresh read of its document.
  • <!-- codebunny-pub:1 k=ce637dd772230b71768ee2d508a35f98b54e34d4ea5e79f1f3859beeada2ca1b -->

    zurfyx zurfyx commented on code on Nov 04, 2026 06:07 UTC
    Code Review
    .changeset/lexical-y-read-merged-under-caret.md:1
    @@ -0,0 +1,7 @@
    +---
    +'@lexical/y': patch
    +---
    +
    +[fix] A remote change read into an editor with a root element runs no node transforms when the text it leaves merges under the caret, so the editor keeps showing what the document stores
    +
    +A read can leave two text nodes side by side that Lexical merges at the end of the update (they differ only in what the binding stores for them), and the caret can be in the second one. The merge moved the caret after the binding had counted the read's selection as notified, so Lexical extended the read's commit with the selection change command and ran every node transform over what the read brought: a code highlight outside a code block, for one, became plain text in that editor only, and stayed so, while every other client and a fresh read of the document showed the code highlight. The read's selection now counts as notified as the merge leaves it.

    Added in 7660f65be.

    meta-code-review[bot] meta-code-review[bot] approved these changes on Nov 04, 2026 06:25 UTC
    Approved Reviewer

    This looks good to me.

    $quietSelection in packages/lexical-y/src/internal/Binding.ts now stores the read's selection itself rather than a copy. That closes the gap where Lexical's end-of-update text merge moved the caret after the copy was taken, so the commit treated it as a selection change and ran every node transform over the content the read brought. The aliasing is bounded: committed selections are frozen in development, every later update builds its own selection, and the SELECTION_CHANGE_COMMAND the binding dispatches after the commit replaces the stored value with a copy again.

    The new regression test sits in src/__tests__/unit/regressions/, as packages/lexical-y/AGENTS.md asks for a bug fix. It reproduces the race with two clients and an outside writer, fails 4 of its 6 cases without the fix, and checks the editor against a fresh read of its document as well as the exact expected structure. Thanks for adding the Verify: paragraph: the changeset now matches what CONTRIBUTING.md and .changeset/README.md ask of a fix that changes editing behavior.

    No further suggestions.

    <!-- codebunny-pub:1 k=965402d2060235545d9f319ea549f97c19569b2103111514e0480fa901f2f24c -->

    Reviewers
    Assignees
    zurfyx zurfyx
    Labels
    risk: low confidence: 83.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52.2% (MEDIUM) · Higher = larger blast radius
    52.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 83.1% · Lower = rushed or shallow review
    83.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 8.8% · Safe to merge
    8.8%
    Repository