Skip to content

[lexical-react] Bug Fix: ExtensionComponent support for output Components with required props#8472

Merged
etrepum merged 4 commits into
facebook:mainfrom
etrepum:claude/fix-extension-required-props-Gn2TJ
May 7, 2026
Merged

[lexical-react] Bug Fix: ExtensionComponent support for output Components with required props#8472
etrepum merged 4 commits into
facebook:mainfrom
etrepum:claude/fix-extension-required-props-Gn2TJ

Conversation

@etrepum

@etrepum etrepum commented May 7, 2026

Copy link
Copy Markdown
Collaborator

Description

The ExtensionComponentProps inference used infer T extends React.ComponentType, which defaults to React.ComponentType<{}>. Because component types are contravariant in their props, any output Component declaring required props was not assignable to ComponentType<{}>, so the conditional type collapsed to never and the JSX element rejected every prop (including the extension itself). Constraining the inference with React.ComponentType<any> lets the inferred type retain its real prop shape.

This fix allows <ExtensionComponent lexical:extension={SomeExtension} {...withRequiredProps} /> to work

Discord discussion

Test plan

New unit tests to confirm that the types don't collapse to never

…s with required props

The ExtensionComponentProps inference used `infer T extends React.ComponentType`,
which defaults to `React.ComponentType<{}>`. Because component types are
contravariant in their props, any output Component declaring required props was
not assignable to `ComponentType<{}>`, so the conditional type collapsed to
`never` and the JSX element rejected every prop (including the extension
itself). Constraining the inference with `React.ComponentType<any>` lets the
inferred type retain its real prop shape.
@vercel

vercel Bot commented May 7, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment May 7, 2026 4:20pm
lexical-playground Ready Ready Preview, Comment May 7, 2026 4:20pm

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 May 7, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label May 7, 2026
@etrepum etrepum marked this pull request as ready for review May 7, 2026 06:14
…ents with required props

useExtensionComponent constrained its inferred OutputComponent through
`Props extends Record<never, never>` and `OutputComponent extends
React.ComponentType<Props>`, which collapses to `ComponentType<{}>`. Because
component types are contravariant in their props, an extension whose output
Component declares required props could not satisfy that constraint and
TypeScript rejected the call. Drop the redundant `Props` parameter and
constrain `OutputComponent` to `React.ComponentType<any>` so the inferred
component type retains its real prop signature. Also extends the existing
ExtensionComponent test suite to cover useExtensionComponent's return type.
… Components with required props

The conditional inferred the output Component as
\`infer C extends React.ComponentType\` (defaulting to
\`React.ComponentType<{}>\`), so any extension whose Component declared required
props failed the contravariant constraint and the conditional collapsed to
\`never\` — making the \`props\` field unassignable. Infer the prop type
directly via \`React.ComponentType<infer P>\` so contravariance never enters
the picture.
Adds type-level and runtime coverage for useExtensionDependency,
useOptionalExtensionDependency, and usePeerExtensionDependency to confirm the
returned `output.Component` retains its real prop signature (including required
props) and that the optional hooks return `undefined | LexicalExtensionDependency`
as documented.
@etrepum etrepum added this pull request to the merge queue May 7, 2026
Merged via the queue into facebook:main with commit d9f9de2 May 7, 2026
70 of 71 checks passed
@etrepum etrepum deleted the claude/fix-extension-required-props-Gn2TJ branch May 8, 2026 00:59
@etrepum etrepum mentioned this pull request May 28, 2026
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. extended-tests Run extended e2e tests on a PR

3 participants