← Back to Pull requests

[lexical] Bug Fix: Put the caret back after a collaboration update when it is in a named slot or another editable island #9978

Closed
unknown closed this pull request without merging on Nov 27, 2026 02:52 UTC
View on GitHub
unknown unknown commented on Nov 24, 2026 14:30 UTC
Author

[!NOTE]

Please merge #9284 first: this builds on it and contains its commits. Only the last commit is new; the rest goes away once #9284 merges.

Description

For an update tagged COLLABORATION_TAG, $updateDOMSelection returns early unless the root element itself has the focus. A caret in a named slot, or in another island marked with $markSlotEditable, focuses that island instead, so after a collaborator's update the selection is never written back to the DOM there. WebKit moves the DOM caret to the start of a text whose content changes, so the next character typed goes to the start of the text. Chromium and Firefox keep the caret in place in this case.

The early return now asks isEditorFocusHost (added in #9284): whether the focused element is the root, or an editable island of this editor inside it. A focused button in the root, or another editor nested in it, still makes the update leave the DOM selection alone.

As for a caret in the root, a collaboration update that moves the DOM caret in an island now also scrolls it into view.

Closes #9955

Changeset

.changeset/collab-caret-in-island.md

Test plan

packages/lexical/src/__tests__/browser/Issue9955CollabCaretInIsland.test.ts puts the caret in the root's own text, in a named slot and in a $markSlotEditable island, writes before it in an update tagged COLLABORATION_TAG, and checks the DOM caret, the focus and where the next key press lands. Two more cases check that the update doesn't take the focus from another editor nested in the root, or from a button in it. The first fails in all three engines, and the second in WebKit, if the check is widened to any element inside the root.

Before

With main's LexicalSelection.ts and LexicalUtils.ts, VITEST_BROWSER=chromium,firefox,webkit pnpm exec vitest --project browser --no-watch --reporter=verbose packages/lexical/src/__tests__/browser/Issue9955CollabCaretInIsland.test.ts (file and describe prefix trimmed). With #9284's source, the same two fail:

 ✓ |browser (webkit)| is where the selection is, in the root's own text 92ms
 ✓ |browser (chromium)| is where the selection is, in the root's own text 50ms
 ✓ |browser (chromium)| is where the selection is, in a named slot's text 24ms
 ✓ |browser (chromium)| is where the selection is, in an editable island's text 22ms
 ✓ |browser (chromium)| stays in another editor nested in the root 6ms
 ✓ |browser (chromium)| doesn't take the focus from a button in the root 5ms
 × |browser (webkit)| is where the selection is, in a named slot's text 127ms
   → expected +0 to be 5 // Object.is equality
 × |browser (webkit)| is where the selection is, in an editable island's text 75ms
   → expected +0 to be 5 // Object.is equality
 ✓ |browser (webkit)| stays in another editor nested in the root 48ms
 ✓ |browser (webkit)| doesn't take the focus from a button in the root 50ms
 ✓ |browser (firefox)| is where the selection is, in the root's own text 59ms
 ✓ |browser (firefox)| is where the selection is, in a named slot's text 20ms
 ✓ |browser (firefox)| is where the selection is, in an editable island's text 15ms
 ✓ |browser (firefox)| stays in another editor nested in the root 22ms
 ✓ |browser (firefox)| doesn't take the focus from a button in the root 8ms
 Test Files  1 failed | 2 passed (3)
      Tests  2 failed | 13 passed (15)

After

 ✓ |browser (chromium)| is where the selection is, in the root's own text 73ms
 ✓ |browser (chromium)| is where the selection is, in a named slot's text 29ms
 ✓ |browser (chromium)| is where the selection is, in an editable island's text 23ms
 ✓ |browser (chromium)| stays in another editor nested in the root 7ms
 ✓ |browser (chromium)| doesn't take the focus from a button in the root 7ms
 ✓ |browser (webkit)| is where the selection is, in the root's own text 99ms
 ✓ |browser (webkit)| is where the selection is, in a named slot's text 31ms
 ✓ |browser (webkit)| is where the selection is, in an editable island's text 31ms
 ✓ |browser (webkit)| stays in another editor nested in the root 44ms
 ✓ |browser (webkit)| doesn't take the focus from a button in the root 50ms
 ✓ |browser (firefox)| is where the selection is, in the root's own text 47ms
 ✓ |browser (firefox)| is where the selection is, in a named slot's text 36ms
 ✓ |browser (firefox)| is where the selection is, in an editable island's text 14ms
 ✓ |browser (firefox)| stays in another editor nested in the root 13ms
 ✓ |browser (firefox)| doesn't take the focus from a button in the root 9ms
 Test Files  3 passed (3)
      Tests  15 passed (15)

VITEST_BROWSER=chromium,firefox,webkit pnpm exec vitest --project browser --no-watch packages/lexical/: the 18 failures are Issue9363SlotDeletion.test.ts, 6 in each engine, and the same 18 fail with main's source on this machine.

 Test Files  3 failed | 99 passed (102)
      Tests  18 failed | 2069 passed | 8 skipped (2095)

pnpm exec vitest --project unit --no-watch packages/lexical/ packages/lexical-react/ packages/lexical-yjs/ packages/lexical-rich-text/ packages/lexical-plain-text/:

 Test Files  198 passed (198)
      Tests  3759 passed | 4 expected fail (3763)

tsc and pnpm run check-changesets pass, and Prettier and ESLint are clean on the changed files. macOS and Windows weren't run.

Diff: 650 lines (+487 / -163) across 8 files Reviewer: potatowagon Review duration: 3622m
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
0.52
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
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.388
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #9978"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% 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% (MEDIUM) · Higher = larger blast radius
52%
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: 60.5% · Lower = rushed or shallow review
60.5%
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: 20.5% · Safe to merge
20.5%
Repository