Repository navigation
fix: direct plain-function component calls crashing in dev compile - #672
Merged
Merged
Conversation
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]>
trueadm
marked this pull request as ready for review
August 9, 2026 22:14
Merged
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A component invoked as a plain function —
Row({ label })inside another component's render, e.g. from a.mapcallback — crashed in dev compile only withCannot 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.mapcall, 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 readscope.blockunconditionally. The runtime always passes the block asscopewhen invoking a body (renderBlockInner), but a plain direct call passes onlyprops, soscopeisundefinedand 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'bodyat 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— thehmr()wrapper registersscope.blockonly whenscope !== 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.mapshape 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'supdate()succeeds (empty live-block set is not a failure) and the call site's output refreshes through the caller's update. ThecompileHmrComponentharness now also strips theexport { X };statement form that verbatim return-JSX functions emit (they don't useexport let)..changeset/hmr-direct-component-call.md— patch changeset foroctane.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(scopedformat:files:checkon changed files; unchanged)pnpm typecheckpnpm test— 17,333/17,334; the single failure ispackages/styled-components/tests/differential/parity.test.tstiming out at 5s under full-suite contention, unrelated to this path, and passing in isolation in 191msvitest 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
loadCompiledFixtureSourceintests/_server-fixture.tscorrupts compiled modules that useexport functiondeclarations (its rewrite drops the hoisted binding, so the compiler's module-tailX.$$singleRoot = truestamp throws aReferenceErrorno real bundler would produce). Flagged for a follow-up task.Provenance
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 readscope.blockeven though direct calls pass only props, soscopewasundefined.The
hmr()wrapper inruntime.tsnow adds a live block only whenscope !== 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 stripsexport { 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.