Turbopack: consume graph-derived chunk groups (#98734)
### What? Next.js output chunking uses the merged chunk groups derived by `ChunkGroupInfo`, rather than reconstructing them in output code: - **Client references** (`app_client_references_chunks.rs`): each layout segment chunks the isolated merged client reference groups the graph derived for its references, with one `chunk_group` call per segment and side (`ssr modules`, `client modules`, using the list form from #99686). There is no manual availability threading or result concatenation. - **Server utilities** (`app.rs`, per-page module graph): the entry's server utilities are chunked as the graph's shared merged group for the entry and the server utility merge tag, instead of a hand-built `SharedMerged` group. - **Ordered traversal**: chunk traversal starts from `ModuleBatchesGraph::get_ordered_entries` for each group, in list order. The chunking API still takes `ChunkGroup` values; this PR passes the groups exactly as the graph registered them. #99750 then switches the API to keys. This is PR 3 of a six-PR stack, based on `canary` (#98733, #99686 and #99749 are already merged): 1. #98823 — Pages Router dev client graph chaining 2. #99910 — regression test for Pages Router `_app` availability (#99789) 3. **This PR** — use graph-derived merged groups 4. #99750 — chunking takes a `ChunkGroupKey` 5. #98685 — chunk-group availability bitmaps 6. #99050 — keyed chunk-group index lookups ### Why? The module graph derives merged parents from actual membership bitmaps. Output code previously guessed a parent and assembled an entry list by hand, which could disagree with the graph for shared client references and framework routes. A segment's client references can derive several merged groups (e.g. one per page rendering the root layout). Chunking each one separately ran one chunking task per group; chunking them together runs one per segment and side. Graph-derived merged entries have unspecified raw order, so chunk traversal must use the postorder `ModuleBatchesGraph` already computes, to preserve CSS evaluation order. ### How? - `ChunkGroupInfo` exposes exact memberships (`get_chunk_groups_for_module`) and the shared merged child of a parent and merge tag (`get_shared_merged_chunk_group`). - `ClientReference` retains its source module (`parent_module`), so merge-tagged groups are scoped to their graph parent. Component-owned references are intersected with their server component's memberships, which prevents collecting across segments, falling back to the source module's groups when the intersection is empty. - The client reference merge tags are shared `pub const`s in `next_client_reference` (`CLIENT_MERGE_TAG`, used by CSS and ecmascript client references, and `SSR_MERGE_TAG`), so producers and the chunking code match on the same values. - The `server side rendering` / `client side rendering` tracing spans are kept around the per-segment chunking. ### Verification - Workspace `cargo clippy --all-targets -D warnings`, `cargo check --workspace --all-targets`, `cargo fmt --check` - Turbopack snapshots: 132 passed, no snapshot changes - `turbo-tasks` + `turbopack-core` + `next-core` unit tests: 364 passed (incl. the new parent-index and merge-tag tests) - Production `layout-segment-chunk-sharing`, with a new assertion that the root layout's client and SSR modules are each chunked by one task. The suite now waits until the trace server has fully read the trace before querying spans. - Turbopack production and dev: `404-page-router`, `app-dir/actions/app-action`, `app-dir/initial-css-order`; production `edge-pages-support` <!-- NEXT_JS_LLM --> <!-- fleet 4f67c6f7-bbe2-454b-9a17-822a60ef8f7e --> Co-authored-by:vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by:
Tobias Koppers <1365881+sokra@users.noreply.github.com>
Showing
This diff is collapsed.
Please
register
or
sign in
to comment