[lexical] Bug Fix: Put the caret back after a collaboration update when it is in a named slot or another editable island #9978
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
potatowagon
Description
For an update tagged
COLLABORATION_TAG,$updateDOMSelectionreturns 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.mdTest plan
packages/lexical/src/__tests__/browser/Issue9955CollabCaretInIsland.test.tsputs the caret in the root's own text, in a named slot and in a$markSlotEditableisland, writes before it in an update taggedCOLLABORATION_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'sLexicalSelection.tsandLexicalUtils.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:After
VITEST_BROWSER=chromium,firefox,webkit pnpm exec vitest --project browser --no-watch packages/lexical/: the 18 failures areIssue9363SlotDeletion.test.ts, 6 in each engine, and the same 18 fail withmain's source on this machine.pnpm exec vitest --project unit --no-watch packages/lexical/ packages/lexical-react/ packages/lexical-yjs/ packages/lexical-rich-text/ packages/lexical-plain-text/:tscandpnpm run check-changesetspass, and Prettier and ESLint are clean on the changed files. macOS and Windows weren't run.