[lexical] Bug Fix: Backspace at the start of the first block no longer throws in a headless editor #9850
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 437 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 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.364
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #9850"
general
weight: 0.35
potatowagon
Description
In an editor with no root element, such as
@lexical/headlessrunning in Node, Bun or JavaScriptCore,editor._windowisnull. Backspace (DELETE_CHARACTER_COMMANDwithisBackward = true) at the start of the first block threwError: window object not found, because$extendSelectionForDeletion(andRangeSelection.modify) calledgetDOMSelection(getWindow(editor)), andgetWindowthrows when there is no window. The model-level$collapseAtStartpath was never reached, so a quote at the top of the document was not turned into a paragraph.Both places now read the editor's own window:
editor._window === null ? null : getDOMSelection(editor._window), the same check$internalCreateRangeSelectionalready uses. With no window there is no DOM selection, so the deletion falls through to the model-only handling. Checkingeditor._window(instead of passingnulltogetDOMSelection) also keeps a headless editor in a browser page from falling back to the globalwindowselection. Mounted editors are unaffected.Closes #9849
Test plan
Before
After
The new headless test runs under
// @vitest-environment node, so there is nodocumentorwindow.prettier --list-different,eslint,tsc,tsc -p tsconfig.test.jsonandscripts/changesets/check.mjspass on this branch. Browsers were not exercised.