Turbopack: fix split_module correctness for app-router - #95522
Turbopack: fix split_module correctness for app-router#95522jimmyhmiller wants to merge 4 commits into
Conversation
Stats from current PR✅ No significant changes detected📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📎 Tarball URLCommit: ab1a79f |
Failing test suitesCommit: ab1a79f | About building and testing Next.js
Expand output● cache-components-dev-warmup - with runtime prefetch configs › initial load › cached data resolves in the correct phase › cached data + short-stale cached data |
d30cfc8 to
f57969c
Compare
|
Not the most elegant approach. But I found that this internal module was causing these problems. I saw that there were a number of other places we added an exception. So I followed suit. |
| .cell()); | ||
| } |
There was a problem hiding this comment.
a824138 to
0440399
Compare
| // Tag the ident with a `ModulePart::Exports` part so tree-shaking's | ||
| // `split_module` opt-out (`!ident.parts.is_empty()`) skips this module. | ||
| // Because of the state of this feature, it is unclear if this is competely | ||
| // the right course of action. Not skipping this causes "Duplicate module idents" | ||
| // errors. |
There was a problem hiding this comment.
It would actually be nice to split this up (though the savings are marginaly(
Why do you get duplicate module idents? Shouldn't the module splitting add (internal part X) to all modules?
There was a problem hiding this comment.
This feels like a more fundamental bug in split_module.
You might have your own custom Module via a module rule that doesn't have a ModulePart in the ident either. Then you'd also run into this bug.
- Don't split the generated __nextjs-internal-proxy. client-reference proxy module. Its exports are all used, so splitting yields no benefit and duplicates its <exports> part in the module graph, tripping the duplicate-ident check in ModuleGraph::from_graphs. - Pass the original comments to each fragment so magic-comment annotations (turbopackChunkingType, turbopackExports) are still parsed. Fragment ASTs keep their original spans, so comments resolve at the same byte positions. Without this, references fall back to defaults (ChunkingType::Shared -> Parallel), breaking app-router layout-segment chunk groups. Add e2e coverage for app-router and pages.
Tag the generated __nextjs-internal-proxy module's ident with ModulePart::Exports so it hits split_module's existing !ident.parts.is_empty() opt-out, instead of matching the module name inside split_module. This keeps the decision at the proxy's construction site in next-core rather than hardcoding a Next.js-specific name in the general-purpose turbopack-ecmascript crate. Behavior is unchanged: the proxy is still not split, avoiding the duplicate <exports> part that tripped the duplicate-ident check in ModuleGraph::from_graphs.
The client-reference proxy ident now carries a ModulePart::Exports suffix (e.g. ` <exports>`), so its source-map source no longer ends with the .mjs/.cjs extension. Match the base name with contains() instead of ends_with() so the proxy frame stays ignore-listed and does not leak into runtime error stacks (fixes use-cache-errors redbox snapshot).
0440399 to
ab1a79f
Compare
Turbopack: fix split_module correctness for app-router
proxy module. Its exports are all used, so splitting yields no benefit
and duplicates its part in the module graph, tripping the
duplicate-ident check in ModuleGraph::from_graphs.
annotations (turbopackChunkingType, turbopackExports) are still
parsed. Fragment ASTs keep their original spans, so comments resolve
at the same byte positions. Without this, references fall back to
defaults (ChunkingType::Shared -> Parallel), breaking app-router
layout-segment chunk groups.