[lexical-react][lexical-devtools-core] Bug Fix: Flow rejects `ref` on `ContentEditable`, `ContentEditableElement` and `TreeView` #10044
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 #10044"
general
weight: 0.35
zurfyx
Description
ContentEditable,ContentEditableElementandTreeViewdeclare their Flowprops as an intersection with
React.RefAttributes, a faithful transliterationof the TypeScript declarations:
That does not mean the same thing in Flow. TypeScript merges the members of an
intersection, so
refis simply one more property of the result. Flow checks avalue against each arm of an intersection separately, and
refappears onneither arm of the props type, so it never becomes a property of the component's
props. Two symptoms follow, depending on the Flow version:
refis missing fromReact.ComponentProps<typeof ContentEditable>, and a nonsenseref={5}isaccepted. The component is still renderable with a
refbecause JSX reads itthrough
React.RefAttributes, so nothing here fails today — the declarationis just wrong and unchecked.
declaration makes
refan extra property and rejects it outright:Passing a
reftoContentEditable— the ordinary way to reach the editableDOM node — is therefore un-typeable there without a suppression.
This change spells the props as an object spread, so
refbecomes one of thecomponent's own properties, which is what the TypeScript declaration means. No
exactness is given up:
TreeView's props stay exact, andContentEditableElementPropswas already inexact. No TypeScript change isneeded or made — this brings the Flow declarations in line with the TypeScript
ones.
ContentEditableElementandTreeVieware the same construct and are fixedalongside
ContentEditable.A second commit adds a smoke assertion that reads
refoffReact.ComponentProps<typeof ContentEditable>. Without it nothing in thisrepository tells the two declarations apart: the existing
<ContentEditable key="c1" ref={divRef} />assertion type-checks either way, sopnpm run flowpasses onmainas well, and a future change that dropsrefagain would break only downstream.
Why downstream cares: www consumes these
.js.flowdeclarations directly andhas been papering over the error with a
$FlowFixMe[incompatible-type]suppression. Because the consuming files are regenerated from this repository on
every sync, each sync deletes the suppression and re-breaks the check there; the
loop repeats until the declaration is fixed here.
Changeset
.changeset/flow-forwardref-ref-spread.md—patchfor@lexical/reactand@lexical/devtools-core, since it changes shipped Flow types. NoVerify:paragraph: CONTRIBUTING.md reserves it for changes to observable output or
behavior, and this is types-only.
Test plan
Before
In this repository, on
main, the new assertion that readsrefoffReact.ComponentProps<typeof ContentEditable>failspnpm run flow:refisnot a property of the props type. (Output not pasted — the host used to prepare
this change has no Node toolchain, so
pnpm run flowcould not be run here.)In Meta's www, whose generated copies of these files are produced from these
sources,
flow statuson the existing test that renders<ContentEditable key="c1" ref={divRef} />:After
In Meta's www, with the same edit applied to the generated copies and the
sync's suppression removal left in place,
flow status:Two deliberately bad call sites were added to that www test and Flow still
rejected both, so the discrimination that version performs is unchanged:
In this repository,
core-tests / integrity (24.x)— which runsci-check(Flow, TypeScript, Prettier, ESLint) — passes on
08884f5with the newassertion in place, along with
changesets,dependency-check,publish,CodeQL, the browser tests and the e2e matrix.
The host used to prepare this change has no Node toolchain, so
pnpm run flowwas not run locally; the
integrityjob on this pull request is the check thatexercises it.