Skip to content

fix(lexical): guard klass.prototype null check in getStaticNodeConfig#8726

Merged
etrepum merged 1 commit into
mainfrom
fix-getstaticnodeconfig-prototype-guard
Jun 20, 2026
Merged

fix(lexical): guard klass.prototype null check in getStaticNodeConfig#8726
etrepum merged 1 commit into
mainfrom
fix-getstaticnodeconfig-prototype-guard

Conversation

@potatowagon

Copy link
Copy Markdown
Contributor

Summary

getStaticNodeConfig() uses the in operator on klass.prototype without checking that it is non-null. When the extends-chain traversal reaches a class whose prototype is undefined (e.g. a functional component or exotic constructor), this throws:

TypeError: Cannot use 'in' operator to search for '$config' in undefined

Fix

Add a null guard so the lookup safely falls through to undefined instead of throwing:

-    PROTOTYPE_CONFIG_METHOD in klass.prototype
+    klass.prototype != null && PROTOTYPE_CONFIG_METHOD in klass.prototype

Context

This is a regression introduced in #8716 (Named-slot typing). The crash surfaces when createEditor() traverses the $config.extends chain and walks past a proper class boundary where klass.prototype is undefined.

getStaticNodeConfig() uses the `in` operator on `klass.prototype` without
checking that it is non-null. When the extends-chain traversal reaches a
class whose prototype is undefined (e.g. a functional component or exotic
constructor), this throws:

  TypeError: Cannot use 'in' operator to search for '$config' in undefined

Add a null guard so the lookup safely falls through to `undefined` instead
of throwing.

Fixes a regression introduced in #8716 (Named-slot typing).
@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 Jun 20, 2026
@vercel

vercel Bot commented Jun 20, 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 Jun 20, 2026 8:49am
lexical-playground Ready Ready Preview, Comment Jun 20, 2026 8:49am

Request Review

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine but I’d like to see an example of an object that is a valid node and crashes without this patch

@etrepum

etrepum commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

AFAICT this only serves to improve the error message, I can't think of a scenario where this fix changes any behavior.

@etrepum etrepum added this pull request to the merge queue Jun 20, 2026
Merged via the queue into main with commit e15c83c Jun 20, 2026
50 checks passed
@potatowagon

potatowagon commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

This seems fine but I’d like to see an example of an object that is a valid node and crashes without this patch

Error:

TypeError: Cannot use 'in' operator to search for '$config' in undefined
  at getStaticNodeConfig (Lexical.dev.js:16476:46)
  at getTransformSetFromKlass (Lexical.dev.js:13616:1)
  at createEditor (Lexical.dev.js:13734:35)
  at xdsInternalHeadlessEditorWithXDSNodes

Possible Root cause: #8716 (Named-slot typing). The getTransformSetFromKlass function traverses the $config.extends chain but doesn't guard against currentKlass.prototype === undefined (reached when the chain walks past a proper class boundary, e.g. to Function.prototype). All 98 failures use xdsInternalHeadlessEditorWithXDSNodescreateEditor.

Fix: OSS guard in getStaticNodeConfig:

- const nodeConfigRecord = PROTOTYPE_CONFIG_METHOD in klass.prototype ? ...
+ const nodeConfigRecord = klass.prototype != null && PROTOTYPE_CONFIG_METHOD in klass.prototype ? ...
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.

2 participants