Repository navigation
[pull] canary from vercel:canary - #2081
Merged
Merged
Conversation
### What? Stops Turbopack from re-chunking every App Router layout segment once per page in production builds. The manually constructed server-utilities chunk group is now only created in development. ### Why? A production build should chunk each shared layout segment exactly once. Instead, a layout segment was chunked again for every endpoint below it. On a small app with four endpoints, the root layout was chunked 4 times and a nested `dashboard` layout 2 times. The emitted output was still shared, so this was wasted build work rather than bigger bundles, which is why output-based tests never caught it. Production already builds a single module graph for the whole app, so the module graph is not what differs between endpoints. The difference comes from the server-utilities chunk group that seeds the layout-segment chain: - It is a `SharedMerged` group whose parent is the current endpoint's entry chunk group. - A merged group's parent is part of its identity, so every endpoint gets a different group (5 chunkings on the same app). - Its result seeds the availability info passed to each layout segment after it. Availability info is part of the chunking task key, so each shared segment ended up with a different key per endpoint and was chunked again. The code comment already said this manual shared chunk exists mainly to help development. That makes sense there: each endpoint has its own module graph in development, and without the group layout segments would share very little across pages. This is PR 0 of the chunk-group stack. The PRs above it are: 1. #98733 — canonical chunk-group identity 2. #98734 — graph-derived output groups 3. #98823 — Pages Router dev client graph chaining 4. #98685 — chunk-group availability bitmaps 5. #99050 — keyed chunk-group index lookups ### How? The manual server-utilities group is now created only in per-page-module-graph mode, which is development. In production the layout-segment chain starts from an endpoint-independent state, so sibling endpoints produce the same chunking task key for a shared segment. The server utilities are then chunked with the entry through the whole-app graph. Development behaves exactly as before. On the same four-endpoint app, a production build now chunks the root layout and the nested layout **once each**, and the manual server-utilities group is gone. Development still creates the group and chunks segments per page, which is expected for on-demand compilation. Adds `test/e2e/app-dir/layout-segment-chunk-sharing`, a root layout and a nested layout that share one module across two sibling pages. It asserts two things: - **Output sharing (Turbopack dev and production):** the shared module is emitted into exactly one server chunk. Webpack builds a self-contained server bundle per route, so this assertion is gated on the bundler, not the mode. - **Work sharing (Turbopack production only):** output sharing alone does not prove the chunking *task* was reused, since a segment could be re-chunked per page with an identical result. The test builds with tracing enabled and uses `next internal query-trace` to count executions of the nested layout's chunking task, which must be exactly one. A cache hit produces no execution span, so the count equals the number of real executions. Development compiles pages on demand with a module graph per page, so repeated chunking is expected there and the assertion is skipped. With the fix reverted, the work-sharing assertion fails with 2 executions, while the output-sharing assertion still passes. ### Performance Measured on a synthetic App Router app: a root layout and a nested `section/layout.tsx`, each importing M modules (~20% `'use client'`), with N trivial sibling pages under `section/`. Cold `next build` with release native builds of both commits (`192fcaf7` vs this PR, one shared JS build); paired runs in ABBA order on an 8 vCPU / 16 GB Vercel Sandbox VM; 95% Student-t intervals on the paired differences. At **800 pages × 1,000 modules per layout**, a dedicated 12-pair run: | metric | Δ | 95% CI | pairs improved | |---|---|---|---| | Turbopack compile time | **−6.3%** (−767 ms) | [−968, −565] ms | 12/12 | | total `next build` time | **−2.2%** (−764 ms) | [−1241, −287] ms | 9/12 | | Turbopack process peak RSS | **−4.2%** (−104 MB) | [−141, −68] MB | 12/12 | In traces of that build, the nested layout goes from 800 chunking executions to 1, the root layout from 802 to 1, and the server-utilities group from 803 to 0 (Node.js chunking spans overall: 7,223 → 1,617). Smaller configurations (50–800 pages × 200 modules, 200 pages × 1,000 modules; 8 pairs each) showed no detected difference in time or Turbopack memory, so the gain matters mainly for large apps. **Trade-off:** without the manual shared group, a few server utilities (the `*-async-storage.external` and `runtime-reacts.external` wrappers, the vendored `react-rsc` getter and a small `bytes` helper) are now inlined into each page's SSR entry chunk instead of being emitted once. That adds about **2.3 KB of server output per App Router endpoint** (+0.9% to +4.4% of server JS in these fixtures). Client JS is byte-identical. Keeping these modules shared in production without per-endpoint identity would be a possible follow-up. ### Verification - Trace measurement on the fixture (production): root layout 4 → 1, nested layout 2 → 1, server-utilities group 5 → 0; dev unchanged - Production build renders and serves every route with the shared module; the shared module is still emitted into exactly one server chunk - `layout-segment-chunk-sharing` — Turbopack production (3 passed), Turbopack dev (output assertion passed, trace assertion skipped), webpack production (Turbopack-only assertions skipped) - `cargo clippy --workspace --all-targets -- -D warnings -A deprecated`, `cargo fmt --all -- --check` - `turbopack-core` + `next-core` unit tests (252 passed); `turbopack-tests` snapshots (126 passed, no changes) <!-- 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>
…erride (#99167) Derived from the conversation over at: #99025 I think `preload` needs that additional caveat. Document the declaration of a font-family. Note that the pattern discussed on that thread is not something we should document, at least I don't think so, I am just expanding the docs on this area.
sonnet reaches context max right after handoff, will follow up reducing the context for same major
…9015) Follow-up to #98003 so that this works with `vc deploy` (or anything else using the adapters API, this isn't a breaking change). Creates "synthetic" symlinks when it needs to rewrite a symlink target (for cross-root links). Potential follow-up: We can potentially extend the adapter API to let us pass the full symlink information to adapters that support it, so that we don't have to create a bunch of synthetic symlink files on disk.
Same-major security and latest updates received migration instructions that could send agents through unnecessary codemods and Pages Router work. Therefore split the docs and provide only the relevant context.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )