Skip to content

fix: $config() synthesized getType() recurses infinitely when inherited as own static (#8867 follow-up) - #8869

Merged
etrepum merged 1 commit into
mainfrom
potatowagon/fix-8867-gettype-recursion
Jul 21, 2026
Merged

etrepum merged 1 commit into
mainfrom
potatowagon/fix-8867-gettype-recursion

Conversation

@potatowagon

@potatowagon potatowagon commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

The problem this solves

After #8867, registering or resolving the type of a $config({extends}) node subclass can infinite-loop and crash with RangeError: Maximum call stack size exceeded — but only under compiled class output (Babel/transpiled bundles, e.g. Meta's www). Any editor that registers such a node (a hashtag node, a code-highlight node, a custom TextNode/ElementNode subclass configured via $config({extends})) fails to initialize.

Concrete breakage (real consumers)

In Meta's www, nodes like HashtagNode and CodeHighlightNode are defined as $config({extends: TextNode}) subclasses. When the Lexical bundle containing #8867 was synced in, 7 previously-green test suites started failing — 118 tests — every one blowing the stack in getType():

RangeError: Maximum call stack size exceeded
  at getStaticNodeConfig            (Lexical.dev.js)
  at Function.getType               (LexicalNode static getType)
  at Function.klass.getType         (#8867 synthesized closure)
  at getStaticNodeConfig            (…loops forever)

Root cause

#8867 fixed a real bug — a subclass inheriting a superclass's synthesized getType() and registering under the wrong type (collision). Its guard defers to the base for a foreign this:

klass.getType = function () {
  if (this !== synthesizedForKlass) {
    return LexicalNode.getType.call(this);   // -> getStaticNodeConfig(this)
  }
  return ownNodeType;
};

But getStaticNodeConfig derives a node's type by calling klass.getType():

const nodeType =
  !isAbstract && hasOwnStaticMethod(klass, 'getType') ? klass.getType() : undefined;

Native ES classes don't inherit statics as own properties — but compiled class output copies the superclass's synthesized closure down onto the subclass as an own static (its captured synthesizedForKlass still points at the superclass). That closes the loop:

getStaticNodeConfig(Sub)
  -> Sub.getType()                    // own, synthesized, synthesizedForKlass = Super
    -> this (Sub) !== synthesizedForKlass (Super)
      -> LexicalNode.getType.call(Sub)
        -> getStaticNodeConfig(Sub)   // back to the top -> stack overflow

Because it only manifests under transpilation, Lexical's own (untranspiled) unit tests — including #8867's collision tests — never caught it.

The fix

Brand the synthesized closure with an internal symbol, and never call a synthesized getType() to derive the type in getStaticNodeConfig — derive it from the $config record instead. A genuine user-defined static getType() is still called exactly as before.

const ownGetType =
  !isAbstract && hasOwnStaticMethod(klass, 'getType') ? klass.getType : undefined;
const nodeType =
  ownGetType && !(SYNTHESIZED_GET_TYPE in ownGetType) ? ownGetType.call(klass) : undefined;

This breaks the cycle while fully preserving #8867's collision fix.

Test plan

  • Added a regression test in LexicalNode.test.ts that reconstructs the compiled shape (a synthesized closure installed as an own static on a subclass whose identity differs from the closure's synthesizedForKlass). It throws RangeError: Maximum call stack size exceeded on main and passes with this fix.
  • tsc -p ./tsconfig.json --noEmit — clean.
  • vitest --project unit LexicalNode.test — 100/100 pass (including fix: $config() synthesized getType() inherited by subclasses causes node-type collision (#8640) #8867's existing collision tests).
  • Validated against the actual compiled bundle: patching the generated Lexical.dev.js with this change in Meta's www and re-running the 7 previously-failing suites takes them from 118 failed / 30 passed to 148 passed / 148 total.

References

Scope

getType() recursion only. Touches the $config() synthesis runtime (LexicalUtils.ts) — disjoint from the separate importJSON nullable BC regression, which is fixed in #8868.

@vercel

vercel Bot commented Jul 21, 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 Jul 21, 2026 12:24pm
lexical-playground Ready Ready Preview Jul 21, 2026 12:24pm

Request Review

@etrepum
etrepum added this pull request to the merge queue Jul 21, 2026
Merged via the queue into main with commit fccc283 Jul 21, 2026
48 checks passed
@etrepum etrepum mentioned this pull request Jul 29, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 8e76c4f1 Deployed Jul 21, 2026 by vercel[bot]
Preview – lexical-playground — 8e76c4f1 Deployed Jul 21, 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