Skip to content

reactCompiler: stack overflow on long call chains; fast_check::is_required unused by transform #12423

Description

Describe the bug

With jsc.transform.reactCompiler enabled, SWC overflows the stack on files that contain long member-call chains (for example generated query builders), even when the file has no React code at all.

Two things combine:

  1. swc_ecma_react_compiler::transform runs the full SWC -> Babel-AST conversion and HIR lowering on every file. fast_check::is_required (made conservative in fix(react-compiler): make fast check conservative #12105) is only used by the Node binding, not by transform, so files that infer/annotation mode can never compile still pay for conversion.
  2. convert_expr in convert_ast.rs (and its reverse) recurse once per chain link without stacker. On a 2 MiB thread (the default for spawned threads, e.g. in rspack workers) a debug build of the crate tests overflows at about 40 links; we saw release builds (via rspack) overflow at roughly 165 links.

Input code

export const value = builder.next().next().next() /* ... ~1000 times ... */ .next();

Config

{ "jsc": { "transform": { "reactCompiler": true } } }

Expected behavior

Files without JSX, hook calls or opt-in directives are left untouched in infer/annotation mode, and long chains in real components do not abort the process.

Actual behavior

thread '<unknown>' has overflowed its stack / fatal runtime error: stack overflow, aborting.

Proposed fix

  • Gate transform on fast_check::is_required for infer and annotation modes (all and syntax stay ungated). PR follows.
  • Separately, wrap the recursive expression conversion in stacker::maybe_grow, as the parser already does.

Version

main at 965c2df (swc_ecma_react_compiler 25.0.0).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions