Repository navigation
Conversation
…ing resolution failure With separateSSRGraph, a "use client" file is parsed under the browser target, so its resolution failure is attributed to the client graph. The failed file never reaches server component boundary registration, so the server graph had no node for it and routes had no edge to the failure. After a rebuild of an unrelated file, the route failure trace found nothing, the route loaded, and its import of the never-bundled component threw at runtime. That request left the route module stuck even after the failure was fixed. Insert a stale server graph placeholder marked as a client component boundary when such a file fails to resolve an import. Route failure traces then cross into the client graph and find the failure. Fixes #40113
|
Updated 10:32 AM PT - Aug 22nd, 2026
❌ @robobun, your commit b989994 has 1 failures in 🧪 To try this PR locally: bunx bun-pr 40115That installs a local version of the PR into your bun-40115 --bun |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 5 included reviews per hour; 1 remains after this review. WalkthroughThe bundler preserves ChangesStale Client Boundary Recovery
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
I reviewed this PR and didn't find any bugs. The fix is well-reasoned with a thorough writeup and a regression test that exercises the full failure→edit→recovery cycle. Because it introduces a new incremental-graph state (a stale server-graph node pre-marked as a client-component boundary before any chunk arrives) and threads a new hook through the bundler↔DevServer dispatch boundary, a human familiar with bake's graph invariants should confirm the placeholder interacts correctly with receiveChunk's found-existing SCB transitions and client_components_added bookkeeping.
What was reviewed
- Verified the hook mirrors
track_resolution_failure's locking/threading pattern (same call site inrun_resolution_for_parse_task, samegraph_safety_lockguard). - Checked
insert_stale+ post-hocis_client_component_boundary = trueis idempotent whether the node already exists, and that the client-graphinsert_emptyprevents thetrace_importspanic at incremental_graph.rs:1206. - Traced the recovery path: when the real reference-proxy chunk lands on the placeholder,
receiveChunk'sfound_existing && scbarm re-marks the flag and pushesclient_components_addedexactly once (the placeholder itself never pushed), matching the no-placeholder flow. - Confirmed
source_pathis captured beforeresolve_import_recordsand consumed beforeparse_result.valueis overwritten.
Extended reasoning...
Overview
This PR fixes a bake dev-server bug (#40113) where, with serverComponents.separateSSRGraph, a route importing a "use client" file whose own import fails to resolve would incorrectly transition to Loaded after an unrelated sibling edit, then run with a missing bundled module and permanently poison its server HMR module registry entry. The fix adds a new DevServerHandle dispatch hook, insert_stale_client_component_boundary, called from run_resolution_for_parse_task's error branch when a browser-target use_directive == Client file fails resolution under separate_ssr_graph. The hook inserts a stale server-graph node flagged is_client_component_boundary and an empty client-graph node so check_route_failures' trace crosses into the client graph and finds the recorded failure. Files touched: src/bundler/bundle_v2.rs (call site + captures), src/bundler/lib.rs (link_interface entry), src/runtime/bake/DevServer.rs (hook impl), src/runtime/bake/dev_server/mod.rs (link_impl wiring), and a new regression test in test/bake/dev/bundle.test.ts.
Security risks
None. This is dev-server-only incremental-graph bookkeeping; no untrusted input parsing, no auth/crypto, no externally reachable surface beyond what already exists.
Level of scrutiny
Medium-high. The diff is small (~50 LOC across four source files) and follows established patterns exactly — the new hook sits alongside track_resolution_failure in the same dispatch table, is called from the same thread context under the same graph_safety_lock debug guard, and composes two existing graph operations. But bake's dual incremental graphs are dense with lifecycle invariants (edge deletion, HMR invalidation, receiveChunk state transitions, client_components_added/removed bookkeeping), and the fix creates a node state that previously did not exist: a stale server node marked as a CCB before any chunk arrives for it. I traced the recovery path through receiveChunk's found_existing arm and it looks correct — the flag is re-set idempotently and client_components_added is pushed once, matching what a fresh insert would have done — but a maintainer who owns this subsystem should confirm there's no other consumer that assumes a CCB-flagged server node always has a corresponding SSR entry or reference-proxy chunk.
Other factors
The PR description is unusually thorough: it names the exact source lines for cause and effect, enumerates the variants checked against the unfixed build (syntax error vs. resolution failure; separateSSRGraph: false), explains why the placeholder key matches the real reference-proxy chunk's key so recovery replaces it in place, and reports running the full bake dev suite (bundle, esm, hot, html, css, response-to-bake-response, incremental-graph-edge-deletion). The test asserts all three phases (initial 500, still 500 after sibling edit, 200 after creating the missing file) with content assertions, not just status codes. The bug-hunting system found nothing. I'm deferring rather than approving only because the incremental-graph state machine is subtle enough that the placeholder's interaction with paths I did not exhaustively trace (e.g. invalidate, edge deletion when the route itself is edited, or the is_rsc flag insert_stale sets on the placeholder) deserves a human sign-off.
|
On the placeholder's interaction with
|
|
Closing as stale: this PR conflicts with main, and its last commit is from 2026-08-22. The branch stays, so the work is not lost. To pick it up again, rebase the branch on main and reopen this PR. |
Problem
serverComponents.separateSSRGraph, a route imports a"use client"file whose own import does not resolve. The route serves the build error page. After an edit to a sibling client component, the next request runs the route and throwsFailed to load bundled module 'components/Sibling.ts'. This is not a dynamic import, and therefore is a bug in Bun's bundler.The route then never recovers:null is not an object (evaluating 'pageModule.streaming').src/bundler/bundle_v2.rs:5885). The failure skips server component boundary registration, so the server graph has no node for the file and the route has no edge to it.check_route_failures(src/runtime/bake/DevServer.rs:2236) traces the route, finds nothing, and marks it loaded.Fix
insert_stale_client_component_boundary.is_client_component_boundary, the placeholder shape the success path creates. Route edges attach to it, and the failure trace crosses from it into the client graph, where the failure is recorded.test/bake/dev/bundle.test.ts, fails on unfixed bun at the post-edit step. Also ran the bake dev suites bundle, esm, hot, html, css, response-to-bake-response, incremental-graph-edge-deletion.Background
"use client"file. A successful parse registers it: a reference proxy stub in the server graph, plus an SSR copy when the graphs are separate. A failed parse or resolve skips that step."use client"syntax errors are attributed to the server graph, so only this resolve path had the hole.Notes
Reproduction (from the issue): a route imports two
"use client"components. One imports./sibling-missing, which does not exist.GET /serves the build error page (correct).GET /previously ran the route and threwthrowNotFoundfor the sibling. The route's server HMR module was cached inPendingstate withexports = null, and nothing ever invalidated it.GET /previously failed withpageModule.streamingon null. With the fix it renders.The step 5 symptom is downstream of step 3: the registry entry for the route module is created before its dependencies parse, and the synchronous
throwNotFoundleaves itPendingwith null exports. With the route held in the failed state, that request never runs, so the registry is never poisoned.Variants checked against the unfixed build:
separateSSRGraph: falsealready behaved correctly for the same reason.The placeholder node is keyed by the file's absolute path, the same key the real reference proxy chunk uses. When the failure clears and the client component bundles, the stub chunk lands on the same node and replaces the placeholder. The hook also ensures a client-graph node exists, because the server-to-client crossing in
trace_importspanics when a boundary has no client-graph file.Pre-existing failure seen while testing:
production > import.meta properties are inlined in catch-all routes during production buildtimes out at 5s under the debug ASAN build, with and without this diff.[review] gate passed · iteration 0 · 5 files touched
fails on main (without fix)
passes on PR (with fix)
diff hotspot
gate history · 1 passed · 0 rejected · iteration 0
evidence per changed file
root cause · written by the author bot
In separate SSR graph mode, a "use client" file is parsed under the browser target, so its resolution failure was recorded only in the client graph while the failed file never registered a server component boundary, leaving the server graph with no node connecting the route to the failure. As a result, the route failure trace found nothing, a rebuild triggered by editing a sibling component cleared the route's failed state, and the route ran against a module that never bundled. The fix adds a dev server hook that inserts a stale server graph node flagged as a client component boundary when …