Skip to content

fix: direct plain-function component calls crashing in dev compile - #672

Merged
trueadm merged 2 commits into
mainfrom
claude/competent-blackwell-4694e9
Aug 9, 2026
Merged

trueadm merged 2 commits into
mainfrom
claude/competent-blackwell-4694e9

Conversation

@trueadm

@trueadm trueadm commented Aug 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A component invoked as a plain function — Row({ label }) inside another component's render, e.g. from a .map callback — crashed in dev compile only with Cannot read properties of undefined (reading 'block'), while the same module worked in prod. The report that surfaced this described it as a compiler miswire ("StampRow's wrapper received StampList's body"), but the emitted module is correctly wired in every permutation (single vs .map call, declaration order, dev/hmr on and off); the actual defect was in the runtime's dev-only HMR wrapper.

In dev compile, exports are rebound to the HMR wrapper (Row = _$hmr(Row)), and the wrapper read scope.block unconditionally. The runtime always passes the block as scope when invoking a body (renderBlockInner), but a plain direct call passes only props, so scope is undefined and the read throws.

Why

Direct plain-function calls of return-JSX components are legal and work in prod, so dev must behave identically. The fix keeps the wrapper transparent to scope-less calls: it registers a live block only when a scope is present.

Deliberately not done: registering the ambient (caller's) block for direct calls. update() repoints registered blocks' body at the wrapper (b.body = wrapper), so ambient registration would graft the callee's wrapper onto the caller's block — the exact "wrapper received the other component's body" miswire the original report described. Direct-call output still refreshes on edit through the caller's own hot update (module re-evaluation rebinds the caller's closure to the new callee); cross-module direct calls stay stale until the caller re-renders, matching React Fast Refresh's limitation for this pattern.

Changes

  • packages/octane/src/runtime.ts — the hmr() wrapper registers scope.block only when scope !== undefined, with a comment explaining why ambient registration would be wrong. Dev-only path; no prod hot-path cost.
  • packages/octane/tests/direct-call-in-list.test.ts + tests/_fixtures/direct-call-in-list.tsx — behavioral regression mounting the compiled module in both the dev and prod vitest projects: the .map shape from the report, a bare direct call, and the callee mounted on its own.
  • packages/octane/tests/hmr.test.ts — an update-path case: a direct-call-only component's update() succeeds (empty live-block set is not a failure) and the call site's output refreshes through the caller's update. The compileHmrComponent harness now also strips the export { X }; statement form that verbatim return-JSX functions emit (they don't use export let).
  • .changeset/hmr-direct-component-call.md — patch changeset for octane.

All three new tests were verified red against the pre-fix runtime (same crash signature as the report) and green with the fix.

Validation

  • pnpm format:check (scoped format:files:check on changed files; unchanged)
  • pnpm typecheck
  • pnpm test — 17,333/17,334; the single failure is packages/styled-components/tests/differential/parity.test.ts timing out at 5s under full-suite contention, unrelated to this path, and passing in isolation in 191ms
  • targeted tests: vitest run packages/octane/tests/direct-call-in-list.test.ts packages/octane/tests/hmr.test.ts (dev + prod projects, 64 tests green)

Risk / follow-ups

  • Cross-module direct-call output does not hot-refresh until the caller re-renders (matches React Fast Refresh; noted in the wrapper comment).
  • Separate finding, not addressed here: loadCompiledFixtureSource in tests/_server-fixture.ts corrupts compiled modules that use export function declarations (its rewrite drops the hoisted binding, so the compiler's module-tail X.$$singleRoot = true stamp throws a ReferenceError no real bundler would produce). Flagged for a follow-up task.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


Note

Low Risk
Small, dev-only HMR path change with targeted regression tests; no production hot-path behavior change.

Overview
Dev compile crashed with Cannot read properties of undefined (reading 'block') when a component was invoked as a plain function (e.g. Row({ label }) in a .map), while production worked. The HMR wrapper always read scope.block even though direct calls pass only props, so scope was undefined.

The hmr() wrapper in runtime.ts now adds a live block only when scope !== undefined, matching production transparency and avoiding miswiring the caller’s block if the ambient scope were registered.

Tests add mount coverage for direct calls in a list, a single call, and standalone mount, plus an HMR test that callee update() succeeds with no live blocks and the caller refresh updates list output. The HMR compile harness strips export { X }; for verbatim return-JSX modules. A patch changeset documents the fix.

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

A component invoked as a plain function (`Row({ label })` inside another
component's render or a `.map` callback) threw "Cannot read properties of
undefined (reading 'block')" in dev compile while working in prod: the
`_$hmr` wrapper read `scope.block` unconditionally, but a direct call has
no scope argument. The wrapper now registers a live block only when a
scope is present and stays call-transparent otherwise. Direct-call output
still refreshes on edit through the caller's own hot update; registering
the ambient block instead would let update() repoint the caller's body at
the callee's wrapper.

Co-Authored-By: Claude Fable 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 Aug 9, 2026
@trueadm
trueadm marked this pull request as ready for review August 9, 2026 22:14
@trueadm
trueadm merged commit 4653a2e into main Aug 9, 2026
34 checks passed
@trueadm
trueadm deleted the claude/competent-blackwell-4694e9 branch August 9, 2026 22:52
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