← Back to Pull requests

[lexical-react][lexical-devtools-core] Bug Fix: Flow rejects `ref` on `ContentEditable`, `ContentEditableElement` and `TreeView` #10044

Closed
unknown closed this pull request without merging on Dec 04, 2026 15:13 UTC
View on GitHub
unknown unknown commented on Dec 04, 2026 13:14 UTC
Author

Description

ContentEditable, ContentEditableElement and TreeView declare their Flow
props as an intersection with React.RefAttributes, a faithful transliteration
of the TypeScript declarations:

declare export const ContentEditable: React.ForwardRefExoticComponent<
  ContentEditableProps & React.RefAttributes<HTMLDivElement>,
>;

That does not mean the same thing in Flow. TypeScript merges the members of an
intersection, so ref is simply one more property of the result. Flow checks a
value against each arm of an intersection separately, and ref appears on
neither arm of the props type, so it never becomes a property of the component's
props. Two symptoms follow, depending on the Flow version:

  • Under the flow-bin 0.343.0 this repository pins, ref is missing from

  • React.ComponentProps<typeof ContentEditable>, and a nonsense ref={5} is
    accepted. The component is still renderable with a ref because JSX reads it
    through React.RefAttributes, so nothing here fails today — the declaration
    is just wrong and unchecked.
  • Under the Flow that Meta's www runs, where the props arm is exact, the same

  • declaration makes ref an extra property and rejects it outright:

      Cannot create `ContentEditable` element because property `ref` is extra in
      `{ref: React.RefObject<HTMLDivElement | null>}` [1] but missing in `...` [2].
      Exact objects do not accept extra props. [incompatible-type]
      

    Passing a ref to ContentEditable — the ordinary way to reach the editable
    DOM node — is therefore un-typeable there without a suppression.

    This change spells the props as an object spread, so ref becomes one of the
    component's own properties, which is what the TypeScript declaration means. No
    exactness is given up: TreeView's props stay exact, and
    ContentEditableElementProps was already inexact. No TypeScript change is
    needed or made — this brings the Flow declarations in line with the TypeScript
    ones.

    ContentEditableElement and TreeView are the same construct and are fixed
    alongside ContentEditable.

    A second commit adds a smoke assertion that reads ref off
    React.ComponentProps<typeof ContentEditable>. Without it nothing in this
    repository tells the two declarations apart: the existing
    <ContentEditable key="c1" ref={divRef} /> assertion type-checks either way, so
    pnpm run flow passes on main as well, and a future change that drops ref
    again would break only downstream.

    Why downstream cares: www consumes these .js.flow declarations directly and
    has 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 — patch for @lexical/react and
    @lexical/devtools-core, since it changes shipped Flow types. No Verify:
    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 reads ref off
    React.ComponentProps<typeof ContentEditable> fails pnpm run flow: ref is
    not a property of the props type. (Output not pasted — the host used to prepare
    this change has no Node toolchain, so pnpm run flow could not be run here.)

    In Meta's www, whose generated copies of these files are produced from these
    sources, flow status on the existing test that renders
    <ContentEditable key="c1" ref={divRef} />:

    Error ----------------- html/shared/lexical/LexicalExtension.flowtest.js.flow:186:6
    
    Cannot create `ContentEditable` element because property `ref` is extra in
    `{ref: React.RefObject<HTMLDivElement | null>}` [1] but missing in `...` [2].
    Exact objects do not accept extra props. [incompatible-type]
    
       html/shared/lexical/LexicalExtension.flowtest.js.flow:186:6
       186|     <ContentEditable key="c1" ref={divRef} />,
                 ^^^^^^^^^^^^^^^
    
    References:
       html/shared/lexical/LexicalExtension.flowtest.js.flow:186:5
       186|     <ContentEditable key="c1" ref={divRef} />,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]
       html/shared/lexical/LexicalContentEditable.js.flow:56:3
        56|   ContentEditableProps & React.RefAttributes<HTMLDivElement>,
              ^^^^^^^^^^^^^^^^^^^^ [2]
    
    Found 1 error
    

    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:

    No errors!
    

    Two deliberately bad call sites were added to that www test and Flow still
    rejected both, so the discrimination that version performs is unchanged:

    <ContentEditable key="neg1" notAProp="x" />,                    // unknown prop
    <ContentEditable key="neg2" placeholder={<div>Type</div>} />,   // placeholder without aria-placeholder
    

    Error ---- html/shared/lexical/LexicalExtension.flowtest.js.flow:187:6
    Error ---- html/shared/lexical/LexicalExtension.flowtest.js.flow:188:6
    Found 2 errors
    

    In this repository, core-tests / integrity (24.x) — which runs ci-check
    (Flow, TypeScript, Prettier, ESLint) — passes on 08884f5 with the new
    assertion 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 flow
    was not run locally; the integrity job on this pull request is the check that
    exercises it.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: zurfyx Review duration: 119m
    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 #10044"
    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