Skip to content

fix(compiler): compile anonymous default-exported @{} components - #1842

Merged
trueadm merged 2 commits into
mainfrom
fix/anonymous-default-component
Oct 7, 2026
Merged

trueadm merged 2 commits into
mainfrom
fix/anonymous-default-component

Conversation

@trueadm

@trueadm trueadm commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

export default function () @{ <p>D</p>; } crashed every DOM compile (client prod, client dev, Vite and webpack HMR, and server) with TypeError: Cannot read properties of null (reading 'name') in compileComponent / compileServerComponent. Component lowering addresses the compiled function through its declaration binding for capability stamps (__s, markWarm), the HMR rebinding, dev __oct_loc, and profile registration. An anonymous default declaration has no binding.

The parenthesized form export default (function () @{ … }) crashed the same way. Found while fixing #1839: #1840 had to use a named default export in its fixture.

Fix. A new copy-on-write pass, nameAnonymousDefaultComponent, runs right after normalizeArrowComponents in both the client (compileInternal) and server (compileServer) pipelines. It gives the anonymous @{} component a synthesized module binding:

  • The name is _default, Babel's convention. It is allocated with the existing allocCompilerName / collectIdentifierNames, so it becomes _default$ and so on when an authored identifier already uses the name.
  • After this pass the module compiles exactly like export default function Name() @{ … }.
  • The public export stays default.
  • HMR registration is keyed by the export name, so hot updates register under default.
  • findVoidComponentExports already certified 'default' for this shape. That claim is now true of the compiled output too, and it matches the analyzeCompiledModule re-proof added in perf(rspack-plugin): specialize imported void roots and component calls in production builds #1840.
  • Async and generator anonymous components are rejected with an error that names default, not the synthesized binding.

Visible naming. The component's fn.name, which runtime diagnostics print, is _default, as in Babel's CJS output. Its profile metadata name is _default too. The profile pipeline uses the metadata name as the registration binding, so the two must match. Native ESM would infer the name default, but every name-carrying shape needs a binding, so that name can't be kept.

Unchanged:

  • The universal (Lynx) compiler, which already names anonymous defaults __octaneUniversalDefault.
  • Volar.
  • export default () => @{ … }, which takes the generic value path. See follow-ups.

Validation

  • Pre-fix failures. Each new test failed with the reported TypeError before the fix:
    • component-mount-shapes.test.ts: the file failed to import its fixture.
    • hmr.test.ts: the two default cases failed.
    • local-void-root.test.ts: the new case failed.
    • void-root-exports.test.ts: the re-proof case failed with the fix unwired.
  • Deliberate breaks. Each check below went red when its piece of the fix was removed, then I restored it:
    • Hard-coding '_default' instead of allocating makes the fixture throw SyntaxError: Identifier '_default' has already been declared. The fixture declares an authored const _default.
    • Dropping the rejectAsyncOrGenerator(…, 'default') call makes the new compile-errors cases fail with Component \_default` is declared…`.
  • Targeted tests, --project octane only, per the local test-load rule: component-mount-shapes, hmr, local-void-root, compiler/compile-errors, compiler/void-root-exports, plus the neighbouring compiler/compile-dev-loc, compiler/compile-profile, compiler/islands-shell, compiler/strong-mode and conformance/server-integration-matrix. All passed: 1,427 tests before the rebase onto perf(rspack-plugin): specialize imported void roots and component calls in production builds #1840, and 150 + 4 on the rebased files.
  • Output equivalence. A scratch comparison script compiled the anonymous form against export default function P(props) for 10 component shapes across 11 modes: prod, dev, vite HMR, webpack HMR, server, server dev, profile, Strong, inspect, and native reads on client and server. The shapes were hooks, use(), <Hydrate> islands, scoped <style>, a null guard, @try, @for, child components, context and derived$. All 110 outputs are byte-identical once the binding name, source-text hashes and the file name are normalized.
  • Hydration keys do not depend on the component name. Client and server compile the same normalized source.
  • pnpm format:files:check on every changed file
  • node scripts/react-parity/check.mjs --validate-only
  • pnpm sync (no generated changes)
  • pnpm typecheck:files on the changed files and fixture. No errors in new code. It still reports two existing errors in untouched code: scope-lazy-collections.tsrx TS7006 and compile-errors.test.ts:573 TS2769.
  • pnpm format:check, pnpm typecheck, pnpm test: left to CI. The octane-prod project was not run locally. The production client compile is exercised by local-void-root (dev: false, hmr: false).

Performance. No runtime or bundle change; the only output change is for input that used to crash. Compile cost per module is one findIndex over top-level statements. An identifier walk runs only when an anonymous default @{} component exists. No benchmark was run because there is no measurable path.

Risk / follow-ups

  • export default () => @{ … } (arrow) still compiles through the generic value path. It works, but it gets no HMR wrapper or accept block and no __s stamp. Normalizing it to the same named form would be a small follow-up.
  • export default (function Name() @{ … }) (a named function expression) emits const Name = …. That collides with an existing module binding Name, which JavaScript semantics would allow. This pre-existing issue is untouched here.
  • perf(rspack-plugin): specialize imported void roots and component calls in production builds #1840's Rspack fixture could now go back to the anonymous default form.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Low Risk
Targeted compiler AST normalization for a previously crashing input shape; no intentional runtime behavior change for code that already compiled, with broad test coverage on client, server, HMR, and bundler void-export paths.

Overview
Fixes a compiler crash when modules use export default function () @{ … }: component lowering expected a declaration binding and threw Cannot read properties of null (reading 'name') on client, server, and HMR builds.

A new copy-on-write AST pass, nameAnonymousDefaultComponent, runs after normalizeArrowComponents on both client and server pipelines. It assigns a collision-safe synthesized id (typically _default, via allocCompilerName) to the anonymous @{} function while keeping the public export as default, so stamps, HMR, dev metadata, and void-root specialization behave like a named default component. Async and generator anonymous defaults are rejected with diagnostics that refer to default, not the synthesized binding.

Tests cover mount/update, SSR, hydration, HMR under default, void-export re-proof, production __createVoidRoot specialization, and a fixture with an authored _default binding to guard name allocation.

Reviewed by Cursor Bugbot for commit 15104d5. Bugbot is set up for automated code reviews on this repo. Configure here.

trueadm and others added 2 commits October 7, 2026 11:37
`export default function () @{ … }` crashed client, server, and HMR compiles
with `Cannot read properties of null (reading 'name')`: component lowering
addresses the compiled function through its declaration binding, and an
anonymous default declaration has none.

Give the anonymous component a synthesized module binding (`_default`,
suffixed past any authored identifier) right after arrow-component
normalization in both the client and server pipelines, so it compiles exactly
like `export default function Name() @{ … }`: capability stamps, dev LOC,
HMR registration under the `default` export, and the void-root contract that
findVoidComponentExports already certified. Async and generator anonymous
components are rejected with an error naming `default`, not the synthesized
binding.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… on its compiled output

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 7, 2026
@trueadm
trueadm marked this pull request as ready for review October 7, 2026 10:40
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No budget breaches, no added work, and no timing changes beyond ±3%.

Compares b8e55da03, the merge commit's first parent with 1c80b856f on the same runner. A byte value over its committed budget or any increase in a js-framework work counter fails this check. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.700 2.767 ±0.0% −0.0% … +3.6% ⚪ within noise
octane-tsrx replace 5.583 5.683 +2.7% −3.4% … +10.0% ⚪ within noise
octane-tsrx add 2.625 2.733 ±0.0% ±0.0% … +6.0% ⚪ within noise
octane-tsrx update 0.118 0.119 −0.3% −2.0% … +1.5% ⚪ within noise
octane-tsrx select 0.006 0.006 +0.8% −0.5% … +2.9% ⚪ within noise
octane-tsrx swap 0.041 0.044 +0.8% −0.8% … +12.9% ⚪ within noise
octane-tsrx remove 0.016 0.018 −0.4% −3.0% … +6.2% ⚪ within noise
octane-tsrx runlots 26.367 26.425 ±0.0% −3.0% … +1.4% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 +0.7% ±0.0% … +1.3% ⚪ within noise
octane-tsrx clear 51.067 52.450 +0.2% −1.0% … +3.2% ⚪ within noise
octane-jsx run 3.542 3.500 ±0.0% −2.7% … +2.9% ⚪ within noise
octane-jsx replace 7.633 8.125 +2.1% −0.8% … +5.8% ⚪ within noise
octane-jsx add 3.833 3.567 −2.9% −3.1% … ±0.0% ⚪ within noise
octane-jsx update 0.275 0.261 −2.4% −5.2% … +3.2% ⚪ within noise
octane-jsx select 0.135 0.146 +1.1% +0.0% … +2.1% ⚪ within noise
octane-jsx swap 0.226 0.228 +0.9% ±0.0% … +3.6% ⚪ within noise
octane-jsx remove 0.195 0.188 −1.2% −6.3% … +1.2% ⚪ within noise
octane-jsx runlots 29.850 28.917 −1.5% −4.2% … +0.5% ⚪ within noise
octane-jsx select_lots 1.573 1.494 −3.6% −5.6% … −0.8% ⚪ within noise
octane-jsx clear 56.842 57.517 +2.7% −1.7% … +6.2% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 60 measured values.

Public-import reachability bundles (bytes)

No changes across 108 measured values.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website 15104d5 Commit Preview URL

Branch Preview URL
Oct 07 2026, 11:00 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website-mcp 15104d5 Commit Preview URL

Branch Preview URL
Oct 07 2026, 11:02 AM

@trueadm
trueadm merged commit ceba949 into main Oct 7, 2026
53 checks passed
@trueadm
trueadm deleted the fix/anonymous-default-component branch October 7, 2026 11:03
trueadm added a commit that referenced this pull request Oct 7, 2026
Conflicts: the 87 react-parity manifests and the user-apps-v1 manifest
record the lockfile hash, which main changed by adding jsdom to the
codegen-size benchmark (#1840); pnpm sync regenerated them. The merged
lockfile needs no changes from `pnpm install --lockfile-only`.

The new anonymous-default-component fixture (#1842) is already in the
new layout and compiles in both modes; #1842's tests pass on this
branch's parser.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant