Skip to content

[lexical] Fix: Flow declarations cannot express an extension with dependencies - #9176

Merged
potatowagon merged 1 commit into
meta:mainfrom
potatowagon:flow-extension-dependency-types
Sep 17, 2026
Merged

potatowagon merged 1 commit into
meta:mainfrom
potatowagon:flow-extension-dependency-types

Conversation

@potatowagon

Copy link
Copy Markdown
Contributor

Description

The hand-maintained Flow declarations cannot express an extension that has
dependencies, so no Flow codebase can build an editor from extensions — the
defineExtension fix in #9132 made the function callable, and this is the
next wall behind it. Three separate problems, all of them in the declarations
rather than the runtime:

  1. A dependency list cannot hold anything.
    NormalizedLexicalExtensionArgument is declared as
    [LexicalExtension<...>, ...Partial<Config>[]]. Flow rejects an array
    spread in a tuple type outright — Cannot spread non-tuple (array type) into tuple type — so the type is an error at its own definition site, and
    every position that uses it (dependencies, configExtension,
    buildEditorFromExtensions) fails with it. Spelled as a union of the one-
    and two-element tuples, it says the same thing in a form Flow accepts.
    (An extension takes at most one config override, so the variadic tail was
    never meaningful.)

  2. No concrete extension satisfies AnyLexicalExtension.
    LexicalExtension is invariant in Name, and AnyLexicalExtension is
    LexicalExtension<any, string, any, any>, so
    LexicalExtension<ReactConfig, '@lexical/react/React', ...> is not a
    subtype of it: string is incompatible with string literal '@lexical/react/React'. dependencies is declared over
    AnyLexicalExtensionArgument[], so a list holding any real extension is an
    error. Name is only ever read (readonly name: Name), so marking it
    covariant — out Name extends string — matches TypeScript's behaviour.

  3. ReactProviderExtension is declared nowhere.
    packages/lexical-react/flow/LexicalReactProviderExtension.js.flow is a
    header comment and nothing else, so the import does not resolve. It is not
    optional in practice: ReactExtension.build invariants when no
    ReactProviderExtension peer is present, so every React-hosted extension
    editor has to list it.

Test plan

  • pnpm flow passes (flow full-check, 0 errors, flow-bin 0.331.0).
  • Adds packages/lexical-extension/flow/LexicalExtension.flowtest.js.flow,
    the same kind of consumer coverage as
    packages/lexical/flow/Lexical.flowtest.js.flow ([lexical] Fix: make the extension Flow types usable (defineExtension was uncallable) #9132) and for the same
    reason: lint-flow compares exported names and flow checks the
    declarations are internally consistent, but nothing composes the API the way
    an application does, which is how all three of these shipped. It builds a
    nested editor from extensions — bare dependency, configExtension
    dependency, inline-tuple dependency, NestedEditorExtension config, and
    variadic buildEditorFromExtensions.
  • Verified the new file fails without the declaration changes (3 errors,
    including the definition-site spread error) and passes with them.
  • Verified downstream against Meta's www checkout, which consumes these
    declarations through its synced copy: with these three fixes applied, a real
    LexicalNestedComposer → NestedEditorExtension +
    LexicalExtensionEditorComposer migration type-checks, lints, and runs
    (nested editor builds inside a DecoratorNode constructor, inherits
    editable from the parent, parentEditor wired). Without them it cannot be
    written at all.

No runtime files are touched.

…endencies

`NormalizedLexicalExtensionArgument` spreads an array into a tuple type, which
Flow rejects at the definition site, so `dependencies`, `configExtension` and
`buildEditorFromExtensions` are all unusable. `LexicalExtension` is also
invariant in `Name`, so no concrete extension is a subtype of
`AnyLexicalExtension` and a dependency list holding a real extension is an
error. `ReactProviderExtension`, which every React-hosted extension editor must
list, is declared nowhere.

Adds consumer coverage in the shape of the Lexical.flowtest.js.flow added in
9132: it builds a nested editor from extensions, which is what none of this
allowed before.
@vercel

vercel Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lexical Ready Ready Preview Sep 17, 2026 4:03am UTC
lexical-playground Ready Ready Preview Sep 17, 2026 4:03am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 17, 2026
@potatowagon
potatowagon added this pull request to the merge queue Sep 17, 2026
Merged via the queue into meta:main with commit 90f4e5f Sep 17, 2026
46 checks passed
@etrepum etrepum mentioned this pull request Sep 17, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 451f19f5 Deployed Sep 17, 2026 by vercel[bot]
Preview – lexical-playground — 451f19f5 Deployed Sep 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants