[turbopack] Inline the chunk group bootstrap in Next.js to drop the per-route runtime#94666
Conversation
Stats from current PR🔴 1 regression
📊 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
📝 Changed Files (10 files)Files with changes:
View diffsapp-page-exp..ntime.dev.jsfailed to diffapp-page-exp..time.prod.jsfailed to diffapp-page-tur..ntime.dev.jsfailed to diffapp-page-tur..time.prod.jsDiff too large to display app-page-tur..ntime.dev.jsfailed to diffapp-page-tur..time.prod.jsfailed to diffapp-page.runtime.dev.jsfailed to diffapp-page.runtime.prod.jsfailed to diffpages-api-tu..time.prod.jsDiff too large to display pages-turbo...time.prod.jsDiff too large to display 📎 Tarball URLCommit: a5aa5a9 |
Tests PassedCommit: a5aa5a9 |
0fb778a to
cd89baf
Compare
fb9cb49 to
4d9e156
Compare
4d9e156 to
473a8cb
Compare
cd89baf to
9475cf8
Compare
473a8cb to
a9756ee
Compare
9475cf8 to
99feb4c
Compare
99feb4c to
741e40d
Compare
a9756ee to
17fcd4e
Compare
741e40d to
7a7cec6
Compare
17fcd4e to
05d9e37
Compare
797e139 to
9a16987
Compare
6c44f9f to
b4a40da
Compare
9a16987 to
830c7a0
Compare
b4a40da to
9ea672c
Compare
7bde6dd to
b266287
Compare
9ea672c to
9fb9b81
Compare
b266287 to
f383bad
Compare
9fb9b81 to
7da768a
Compare
f383bad to
f4a9fbe
Compare
a79706e to
e11f239
Compare
8a3db7e to
9b8e3dc
Compare
e11f239 to
158bce5
Compare
3710e34 to
bf07da2
Compare
| // Run a navigated route's inlined bootstrap so its entry module executes and | ||
| // registers via `window.__NEXT_P`. The initial page is bootstrapped in the document. |
There was a problem hiding this comment.
Is this used for navigation? Or initial page load? Or both?
| ): string | undefined { | ||
| const paramsByPage = buildManifest.pagesChunkGroupBootstrapParams | ||
| const chunkLoadingGlobal = buildManifest.chunkLoadingGlobal | ||
| if (!paramsByPage || !chunkLoadingGlobal) return undefined |
| `(globalThis[${g}] || (globalThis[${g}] = [])).push(${params});` | ||
| ) | ||
|
|
||
| return statements.length > 0 ? statements.join('\n') : undefined |
There was a problem hiding this comment.
Can statements.length be 0? Should this be able to return undefined?
There was a problem hiding this comment.
yeah, because this is feature flagged now this is possible
| '/_app', | ||
| __NEXT_DATA__.page, | ||
| ]) | ||
| if (!bootstrap) return null |
There was a problem hiding this comment.
Should it actually be possible for getTurbopackChunkGroupBootstrap to return null or undefined?
| if (bootstrappedRoutes.has(route)) return | ||
| const params = self.__TURBOPACK_PAGE_BOOTSTRAP?.[route] | ||
| const global = self.__TURBOPACK_CHUNK_LOADING_GLOBAL | ||
| if (params == null || !global) return |
| const errorBootstrapScriptContent = process.env.__NEXT_DEV_SERVER | ||
| ? bootstrapScriptContent | ||
| : getTurbopackChunkGroupBootstrap(buildManifest, [ | ||
| UNDERSCORE_NOT_FOUND_ROUTE_ENTRY, | ||
| ]) |
There was a problem hiding this comment.
Is this meaningfully different than bootstrapScriptContent above? Is page !== UNDERSCORE_NOT_FOUND_ROUTE_ENTRY
There was a problem hiding this comment.
yes - bootstrapScriptContent would be for the original page you were requesting before the error happened
| const paramsByRoute = m.pagesChunkGroupBootstrapParams | ||
| if (!paramsByRoute) continue |
There was a problem hiding this comment.
This parameter in SerializedBuildManifest is not nullable?
bf07da2 to
9a9f1a6
Compare
8baa0f5 to
e1517db
Compare
9a9f1a6 to
b321f68
Compare
e1517db to
3c77fb8
Compare
b321f68 to
a5aa5a9
Compare
…text` and `chunk_group_bootstrap_params` to `ChunkGroupResult` (#94661) We used to generate the runtime file for each `ChunkGroupResult` in `evaluated_chunk_group()`, I've added `chunk_group_bootstrap_params` which are the parameters that were unique to each chunk group. These are inlined into each page's HTML in #94666. They look like: ```javascript {"otherChunks":["output/0_9x_turbopack-tests_tests_snapshot_basic-tree-shake_export-namespace_input_1mqgz2-._.js"], "runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/input/index.js [test] (ecmascript)"]} ``` Whether or not the inline-able code is generated is based on the `inline_chunk_group_bootstrap` which is still false in all cases at the moment but will be turned to true in #94666.
This PR builds on top of the other PRs in this stack, it is the PR that switches to inlining the bootstrap code and dropping the runtime file that each route had.