Repository navigation
perf(pages-router): load Next.js-like client chunks - #4726
james-elicx wants to merge 71 commits into
Conversation
@vinext/cloudflare
create-vinext-app
@vinext/types
vinext
@cloudflare/workers-response-store
commit: |
Performance benchmarksCompared 0 improved · 0 regressed · 7 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
|
17c6cc1 to
b371b8e
Compare
|
/bigbonk review for issues Please review exact head |
| const rolldownOptions = environment.config.build.rolldownOptions; | ||
| return withInlineCommonChunks(output, { | ||
| preserveEntrySignatures: pagesClientPreserveEntrySignatures, | ||
| onDemandWrapping: (rolldownOptions.experimental as { onDemandWrapping?: unknown }) |
There was a problem hiding this comment.
environment.config.build.rolldownOptions does not include changes made by other plugins in their options hooks. If a plugin enables inputOptions.experimental.onDemandWrapping there, this check misses it and vinext adds experimentalInlineCommonChunks; Rolldown then rejects the otherwise-valid build with INVALID_OPTION. Capture the effective inputOptions.experimental?.onDemandWrapping in the existing post-order options hook alongside preserveEntrySignatures, and pass that captured value here.
There was a problem hiding this comment.
Fixed in e43a422. The post-order options hook now captures onDemandWrapping from the effective input options, next to preserveEntrySignatures, and the outputOptions hook checks those captured values. A new test in tests/pages-client-chunks.test.ts adds a plugin that turns onDemandWrapping on from its options hook. Without the fix, that build fails with Rolldown's INVALID_OPTION. With it, the build succeeds and the shared module keeps its own chunk.
| } | ||
| }, | ||
| outputOptions: { | ||
| // Sees the client output after other plugins' outputOptions hooks. |
There was a problem hiding this comment.
order: "post" only runs after normal hooks; a post-order outputOptions hook from a plugin placed after vinext() still runs later. Such a plugin can validly set an incompatible option (for example strictExecutionOrder: false) after this hook enables experimentalInlineCommonChunks, causing Rolldown to fail with INVALID_OPTION. Please ensure this compatibility check runs after every output mutation, or conservatively skip inlining when a later output-options hook may change these guarded values.
There was a problem hiding this comment.
Partly fixed in e43a422: the plugin is now enforce: "post", so its post-order options and outputOptions hooks run after those of every normal-order plugin, including user plugins.
I'm leaving the remaining case alone on purpose. That's a plugin that is itself enforce: "post", listed after vinext(), that sets one of the incompatible options from its own post-order hook. Handling it would mean inspecting the sorted plugin list, which vinext doesn't do for its other output defaults. If it happens, Rolldown fails the build with an INVALID_OPTION error that names the conflicting option, and disableNextLikeChunking: true turns the inlining off.
|
Review: 2 findings. Posted 2 actionable inline comments on exact head |
|
/bigbonk review for issues Please review exact head |
| // to avoid leaking into RSC/SSR environments. | ||
| ...(!isSSR && !isMultiEnv ? { output: getClientOutputConfig() } : {}), | ||
| ...(!isSSR && !isMultiEnv | ||
| ? { output: getClientOutputConfig(pagesClientCodeSplitting) } |
There was a problem hiding this comment.
Library builds still receive the new Pages-specific group here. Although build.lib prevents the dedicated application environments from being injected above, this standalone-output branch remains unconditional and passes pagesClientCodeSplitting; I reproduced a library entry that dynamically imports pages/_app.tsx, and it now emits a pages-app chunk. That changes library chunking despite this feature being scoped away from library builds. Please retain clientCodeSplittingConfig for build.lib (and avoid collecting roots/inlining there).
There was a problem hiding this comment.
Fixed in 2f21f0c. With build.lib set, the single-output client config now keeps vinext's plain clientCodeSplittingConfig. The plugin's buildEnd also skips collecting roots for library builds. Inlining was already off there, because the outputOptions hook only acts on outputs that still hold the pages-app group. A new test in tests/pages-client-chunks.test.ts builds a library entry that dynamically imports pages/_app.tsx and checks that no pages-app chunk is emitted. Without the fix, that test fails.
|
Since last review: 2 resolved, 0 still open, 1 new. Posted 1 actionable inline finding on exact head |
|
/bigbonk review for issues Please review exact head |
|
error: Your local changes to the following files would be overwritten by checkout: |
|
@james-elicx Bonk workflow timed out. View workflow run · To retry, trigger Bonk again. |
Pages Router production builds loaded 14-23 JS files per route on the pages-router-complex fixture, against 5-6 for Next.js webpack and 10 for Turbopack. Two causes: - `_app`'s imports split into many chunks: a module that `_app` and some pages both import got a shared chunk of its own, though every page loads `_app`. vinext:pages-client-chunks now puts `_app` and its static imports in one "pages-app" chunk, as Next.js keeps `pages/_app` unsplit. - Small modules shared by different sets of pages each got a tiny common chunk. With Rolldown 1.2.18+, small common chunks (under 20 kB, Next.js' webpack `minSize`) are now copied into their importers through `codeSplitting.experimentalInlineCommonChunks`. Each module still evaluates once and only when imported, as in webpack and Turbopack. Stylesheets keep their own chunk, as Turbopack keeps a shared CSS module in one stylesheet. `disableNextLikeChunking` turns both off. Hybrid App + Pages builds keep their current chunking. The pages-router-complex fixture gains workbench desks that produce a varied client chunk graph (shared panels, a 36 kB shared table, local vendor packages, next/dynamic, React.lazy, on-demand imports, next/image, next/script, next/form, next/navigation) with e2e specs, including one that checks a module copied into several page chunks evaluates once.
2f21f0c to
f6014d6
Compare
|
/bigbonk review for issues Please review exact head |
1 similar comment
|
/bigbonk review for issues Please review exact head |
|
Since last review: 1 resolved, 0 still open, 0 new. |
There was a problem hiding this comment.
Superseded by the review of
c24e8f0b.
This review, of f6014d6f
✅ Approved — No issues found. The chunking changes, inlining guards and SSR-manifest CSS ordering are consistent and covered by tests, and the issues raised in earlier rounds are fixed.
Not opened by the correctness review: 51 changed files it was meant to read
examples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/arrow.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/box.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/glyph.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/ledger.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/person.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/truck.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/unused.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-glyphs/index.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/package.jsonexamples/pages-router-complex/__test_packages__/atlas-grid-kit/grid-kit.module.cssexamples/pages-router-complex/__test_packages__/atlas-grid-kit/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-grid-kit/index.jsexamples/pages-router-complex/__test_packages__/atlas-grid-kit/package.jsonexamples/pages-router-complex/__test_packages__/atlas-legacy-format/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/index.jsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/lib/pad.jsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/package.jsonexamples/pages-router-complex/lib/workbench/data/region-table.tsexamples/pages-router-complex/lib/workbench/desk-layout.tsxexamples/pages-router-complex/lib/workbench/export-menu.tsxexamples/pages-router-complex/lib/workbench/export/csv.tsexamples/pages-router-complex/lib/workbench/filter-bar.tsxexamples/pages-router-complex/lib/workbench/format/currency.tsexamples/pages-router-complex/lib/workbench/format/durations.tsexamples/pages-router-complex/lib/workbench/page-data.tsexamples/pages-router-complex/lib/workbench/panel.module.cssexamples/pages-router-complex/lib/workbench/panel.module.css.d.tsexamples/pages-router-complex/lib/workbench/reporting/breakdown-table.tsxexamples/pages-router-complex/lib/workbench/reporting/live-ticker.tsxexamples/pages-router-complex/lib/workbench/reporting/shared-axis.tsexamples/pages-router-complex/lib/workbench/reporting/trend-chart.tsxexamples/pages-router-complex/lib/workbench/reporting/trend-legend.tsxexamples/pages-router-complex/lib/workbench/status-pill.tsxexamples/pages-router-complex/lib/workbench/summary-strip.tsxexamples/pages-router-complex/lib/workbench/tools/diff-engine.tsexamples/pages-router-complex/lib/workbench/tools/presets.jsonexamples/pages-router-complex/lib/workbench/use-hydrated.tsexamples/pages-router-complex/next.config.jsexamples/pages-router-complex/package.jsonexamples/pages-router-complex/pages/[zone]/workbench/desk.module.cssexamples/pages-router-complex/pages/[zone]/workbench/desk.module.css.d.tsexamples/pages-router-complex/pages/[zone]/workbench/dispatch.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/index.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/inventory.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/ledger.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/media.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/reports.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/roster.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/search.page.tsx- … and 1 more
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security issues found.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
No issues found in the chunk-group selection, the plugin lifecycle, the inlining guards or the SSR-manifest CSS reordering. The graph walks guard against cycles, the plugin clears its roots between builds, and the guards match the Rolldown option conflicts the description lists.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: f6014d6f
Shared stylesheets that the same pages import keep a chunk of their own once together they hold 20 kB of CSS, as webpack's minSize does for CSS, instead of every stylesheet keeping its chunk. A stylesheet that only _app imports stays in _app's chunk rather than a JavaScript stub of its own.
There was a problem hiding this comment.
Superseded by the review of
91832d58.
This review, of c24e8f0b
✅ Approved — No issues found. The new stylesheet-size threshold for inlining is consistent with the code and covered by fixtures and unit tests. Earlier issues stay fixed.
Not opened by the correctness review: 47 changed files it was meant to read
examples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/arrow.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/box.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/glyph.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/ledger.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/person.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/truck.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/unused.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-glyphs/index.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/package.jsonexamples/pages-router-complex/__test_packages__/atlas-grid-kit/grid-kit.module.cssexamples/pages-router-complex/__test_packages__/atlas-grid-kit/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-grid-kit/package.jsonexamples/pages-router-complex/__test_packages__/atlas-legacy-format/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/index.jsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/lib/pad.jsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/package.jsonexamples/pages-router-complex/lib/workbench/data/region-table.tsexamples/pages-router-complex/lib/workbench/desk-layout.tsxexamples/pages-router-complex/lib/workbench/export-menu.tsxexamples/pages-router-complex/lib/workbench/export/csv.tsexamples/pages-router-complex/lib/workbench/filter-bar.tsxexamples/pages-router-complex/lib/workbench/format/currency.tsexamples/pages-router-complex/lib/workbench/format/durations.tsexamples/pages-router-complex/lib/workbench/page-data.tsexamples/pages-router-complex/lib/workbench/panel.module.cssexamples/pages-router-complex/lib/workbench/panel.module.css.d.tsexamples/pages-router-complex/lib/workbench/reporting/breakdown-table.tsxexamples/pages-router-complex/lib/workbench/reporting/live-ticker.tsxexamples/pages-router-complex/lib/workbench/reporting/shared-axis.tsexamples/pages-router-complex/lib/workbench/reporting/trend-chart.tsxexamples/pages-router-complex/lib/workbench/reporting/trend-legend.tsxexamples/pages-router-complex/lib/workbench/status-pill.tsxexamples/pages-router-complex/lib/workbench/summary-strip.tsxexamples/pages-router-complex/lib/workbench/tools/diff-engine.tsexamples/pages-router-complex/lib/workbench/tools/presets.jsonexamples/pages-router-complex/pages/[zone]/workbench/desk.module.cssexamples/pages-router-complex/pages/[zone]/workbench/desk.module.css.d.tsexamples/pages-router-complex/pages/[zone]/workbench/dispatch.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/index.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/inventory.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/ledger.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/media.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/reports.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/roster.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/search.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/tools.page.tsx
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
This pull request changes only build configuration, fixtures and tests. No secrets are used in CI, and nothing here can be exploited.
📖 AGENTS.md: ✅ LGTM
The new AGENTS.md entry matches the shared-stylesheet behaviour in this commit.
📋 Code Quality: ✅ LGTM
No issues found in the new handling of stylesheet sizes, the _app-only stylesheet guard, the SSR-manifest backfill or the new fixtures and tests.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: c24e8f0b
…he request repros
|
Thanks for classifying the shared chunks on the app. Here's where each case in a87328a stands at 48b445a. Fixed (fa88a5a)
Vite / Rolldown limitations: not worked around (dda7c10 marks them
If Rolldown or Vite add support for these, the On the 6 Deploy jobs that failed at a87328a: those were Cloudflare API 429s, not this change. |
|
/bigbonk Please review exact head |
There was a problem hiding this comment.
Superseded by the review of
7045eec4.
This review, of 48b445a3
✅ Approved — Both findings from the last review (the failing repro spec and the leaked response listener) are fixed, and the code changed since then shows no new problems.
Not opened by the correctness review: 31 changed files it was meant to read
examples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/arrow.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/box.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/ledger.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/person.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/truck.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/unused.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-grid-kit/grid-kit.module.cssexamples/pages-router-complex/__test_packages__/atlas-grid-kit/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/lib/pad.jsexamples/pages-router-complex/lib/workbench/export/csv.tsexamples/pages-router-complex/lib/workbench/format/currency.tsexamples/pages-router-complex/lib/workbench/format/durations.tsexamples/pages-router-complex/lib/workbench/panel.module.cssexamples/pages-router-complex/lib/workbench/reporting/breakdown-table.tsxexamples/pages-router-complex/lib/workbench/reporting/shared-axis.tsexamples/pages-router-complex/lib/workbench/reporting/trend-legend.tsxexamples/pages-router-complex/lib/workbench/status-pill.tsxexamples/pages-router-complex/lib/workbench/summary-strip.tsxexamples/pages-router-complex/lib/workbench/tools/presets.jsonexamples/pages-router-complex/pages/[zone]/workbench/desk.module.cssexamples/pages-router-complex/pages/[zone]/workbench/desk.module.css.d.tsexamples/pages-router-complex/pages/[zone]/workbench/dispatch.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/index.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/inventory.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/ledger.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/media.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/reports.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/roster.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/search.page.tsx
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
Client stylesheet switching only fetches hrefs from the build-time manifest. It inserts the CSS as text nodes, and the rewritten url() values are JSON-quoted. On the server, the nonce and the attributes on the <link> and <noscript> tags are escaped. The deployment ID query on stylesheet URLs does not change anything security-relevant.
📖 AGENTS.md: ✅ LGTM
The AGENTS.md entry matches what the code does.
📋 Code Quality: ✅ LGTM
Both earlier findings are fixed:
- The repro cases in
shared-requests.spec.tsthat can't pass yet are markedtest.fail(), each with its reason. loadScriptsnow removes its listener withpage.offin afinally.
The changes to client-build-config.ts, index.ts and tests/pages-client-chunks.test.ts look correct, and the fixtures match what their specs expect.
⚡ Performance: ✅ LGTM
The new graph helpers in client-build-config.ts run once per client build and visit each module only once per pass. That cost is acceptable for build-time code.
📝 Documentation: ✅ LGTM
The documentation still matches the code.
Reviewed commit: 48b445a3
| uncopied: pagesUncopiedModules, | ||
| declaresSideEffects: createSideEffectsDeclarationCheck(), | ||
| // `_app` takes from those only what stays in "pages-app". | ||
| importsNothingFrom: (importer, id) => importer === appId && leavingAppGroup.has(id), |
There was a problem hiding this comment.
importsNothingFrom only suppresses a direct _app -> leavingAppGroup edge. With _app -> layout -> side-effect-free barrel and pages consuming another barrel export, layout remains in pages-app while the barrel is marked as leaving, so layout -> barrel is still counted as an always-loaded importer. The duplicate-copy analysis then excludes the page-only export from inlining and adds a standalone request. I reproduced the emitted behavior with the bundled Rolldown 1.2.19: normal inlining put unit into both page chunks, while excluding it emitted a separate unit.js. Suppress edges crossing from the retained app group into the leaving subtree (not only edges whose importer is appId) and add an indirect-layout fixture.
There was a problem hiding this comment.
Fixed in 5e11479. importsNothingFrom now ignores any edge from a module that stays in "pages-app" (_app or one of its retained imports) into the subtree that leaves it, not only edges from _app. In the pages-client-chunks fixture, _app's HomeLink now imports kitTitle from the side-effect-free lib/kit barrel, and pages import kitBadge from it. The fixture test now asserts that kit-badge is copied into alpha and beta. Without the fix it gets a file of its own. The direct _app → barrel shape is still covered by the indexes e2e case.
|
|
||
| // Vite limitation: Vite gives every JavaScript chunk a stylesheet of its own, | ||
| // so the CSS of each list's chunk can't stay in the page's stylesheet. | ||
| test.fail( |
There was a problem hiding this comment.
Declaring these cases with test.fail(title, body) marks the whole test as expected to fail before navigation and hydration. An unrelated route, hydration, or response-read regression therefore still produces the expected status and passes CI. Collect the measurements first, then call test.fail() immediately before the parity assertion(s); apply the same pattern to the other three expected-failure cases below.
There was a problem hiding this comment.
Fixed in 7045eec. Each of the four cases now takes its measurements first and calls test.fail() just before the parity assertions, with the limitation explained next to it. A navigation, hydration or response-read failure now fails the test.
|
Review: 2 findings. Posted 2 actionable inline comments. |
…eaves of a side-effect-free barrel
|
/bigbonk Please review exact head |
There was a problem hiding this comment.
Superseded by the review of
f54d92f5.
This review, of 7045eec4
💬 Approved with comments — The changes since the last review are correct. The one remaining note is an optional defensive fix in the new leaving-app-group walk.
Findings: 1 suggestion (1 is an inline comment on the diff)
Not opened by the correctness review: 31 changed files it was meant to read
examples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/arrow.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/box.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/ledger.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/person.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/truck.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/unused.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-grid-kit/grid-kit.module.cssexamples/pages-router-complex/__test_packages__/atlas-grid-kit/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/lib/pad.jsexamples/pages-router-complex/lib/workbench/export/csv.tsexamples/pages-router-complex/lib/workbench/format/currency.tsexamples/pages-router-complex/lib/workbench/format/durations.tsexamples/pages-router-complex/lib/workbench/panel.module.cssexamples/pages-router-complex/lib/workbench/reporting/breakdown-table.tsxexamples/pages-router-complex/lib/workbench/reporting/shared-axis.tsexamples/pages-router-complex/lib/workbench/reporting/trend-legend.tsxexamples/pages-router-complex/lib/workbench/status-pill.tsxexamples/pages-router-complex/lib/workbench/summary-strip.tsxexamples/pages-router-complex/lib/workbench/tools/presets.jsonexamples/pages-router-complex/pages/[zone]/workbench/desk.module.cssexamples/pages-router-complex/pages/[zone]/workbench/desk.module.css.d.tsexamples/pages-router-complex/pages/[zone]/workbench/dispatch.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/index.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/inventory.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/ledger.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/media.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/reports.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/roster.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/search.page.tsx
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 1 suggestion
The new code is correct. One optional suggestion: guard the getModuleInfo lookups in the leavingAppGroup walk.
Recommendation: 💬 Optional Nits
- [SUGGESTION] The
leavingAppGroupwalk assertsgetModuleInfo(id)!, but theappGroupModuleswalk that fills it reads the same info with?.. (packages/vinext/src/index.ts:9867)
View full review
The new importsNothingFrom predicate does what the description and the HomeLink → lib/kit fixture say it should. shared-requests.spec.ts now takes its measurements before calling test.fail(), so a navigation or hydration failure still fails the test.
One small note. The new leavingAppGroup walk uses this.getModuleInfo(id)!. Two lines above it, the walk that fills appGroupModules reads the same info with ?.importedIds ?? []. That walk adds every id it reaches, including ids that may have no module info, such as externals. Reading the info the same defensive way in both walks would keep the build from throwing in buildEnd in that case.
✅ All other checks passed
🔒 Security: ✅ LGTM
The changes since the last review are limited to build-time chunk grouping and test fixtures. None of them is security-relevant.
📖 AGENTS.md: ✅ LGTM
The AGENTS.md entry matches what the code does.
⚡ Performance: ✅ LGTM
The new walk visits each module in the _app group once per client build. That cost is fine for build-time code.
📝 Documentation: ✅ LGTM
The documentation still matches what the code does.
Reviewed commit: 7045eec4
| const leaving = [...appGroupModules].filter((id) => | ||
| this.getModuleInfo(id)!.importers.some( | ||
| (importer) => importer !== appId && !appGroupModules.has(importer), | ||
| ), | ||
| ); | ||
| while (leaving.length > 0) { | ||
| const id = leaving.pop()!; | ||
| if (leavingAppGroup.has(id)) continue; | ||
| leavingAppGroup.add(id); | ||
| for (const imported of this.getModuleInfo(id)!.importedIds) { | ||
| if (appGroupModules.has(imported)) leaving.push(imported); | ||
| } | ||
| } |
There was a problem hiding this comment.
💬 SUGGESTION · Code Quality
The leavingAppGroup walk asserts getModuleInfo(id)!, but the appGroupModules walk that fills it reads the same info with ?..
appGroupModules is filled from this.getModuleInfo(id)?.importedIds ?? [] at line 9839. That walk adds every id it reaches without checking that the id has module info, for example a module the client build externalizes. Lines 9867 and 9875 then dereference getModuleInfo(id)! for each of those ids. If one has no info, buildEnd throws and the client build fails. Using ?. with a ?? [] fallback here, as line 9839 does, avoids that.
| const leaving = [...appGroupModules].filter((id) => | |
| this.getModuleInfo(id)!.importers.some( | |
| (importer) => importer !== appId && !appGroupModules.has(importer), | |
| ), | |
| ); | |
| while (leaving.length > 0) { | |
| const id = leaving.pop()!; | |
| if (leavingAppGroup.has(id)) continue; | |
| leavingAppGroup.add(id); | |
| for (const imported of this.getModuleInfo(id)!.importedIds) { | |
| if (appGroupModules.has(imported)) leaving.push(imported); | |
| } | |
| } | |
| const leaving = [...appGroupModules].filter((id) => | |
| (this.getModuleInfo(id)?.importers ?? []).some( | |
| (importer) => importer !== appId && !appGroupModules.has(importer), | |
| ), | |
| ); | |
| while (leaving.length > 0) { | |
| const id = leaving.pop()!; | |
| if (leavingAppGroup.has(id)) continue; | |
| leavingAppGroup.add(id); | |
| for (const imported of this.getModuleInfo(id)?.importedIds ?? []) { | |
| if (appGroupModules.has(imported)) leaving.push(imported); | |
| } | |
| } |
There was a problem hiding this comment.
Applied in f54d92f. Both reads in the leaving walk now use ?. with a ?? [] fallback, as the appGroupModules walk does.
|
LGTM! |
|
/bigbonk Please review exact head |
|
LGTM! |
There was a problem hiding this comment.
Superseded by the review of
aa678729.
This review, of f54d92f5
✅ Approved — The defensive module-info fix from the last review is in, and I found no new problems in the changed code.
Not opened by the correctness review: 31 changed files it was meant to read
examples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/arrow.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/box.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/ledger.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/person.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/truck.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/unused.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-grid-kit/grid-kit.module.cssexamples/pages-router-complex/__test_packages__/atlas-grid-kit/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/lib/pad.jsexamples/pages-router-complex/lib/workbench/export/csv.tsexamples/pages-router-complex/lib/workbench/format/currency.tsexamples/pages-router-complex/lib/workbench/format/durations.tsexamples/pages-router-complex/lib/workbench/panel.module.cssexamples/pages-router-complex/lib/workbench/reporting/breakdown-table.tsxexamples/pages-router-complex/lib/workbench/reporting/shared-axis.tsexamples/pages-router-complex/lib/workbench/reporting/trend-legend.tsxexamples/pages-router-complex/lib/workbench/status-pill.tsxexamples/pages-router-complex/lib/workbench/summary-strip.tsxexamples/pages-router-complex/lib/workbench/tools/presets.jsonexamples/pages-router-complex/pages/[zone]/workbench/desk.module.cssexamples/pages-router-complex/pages/[zone]/workbench/desk.module.css.d.tsexamples/pages-router-complex/pages/[zone]/workbench/dispatch.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/index.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/inventory.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/ledger.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/media.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/reports.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/roster.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/search.page.tsx
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The changes cover build-time chunk grouping, client stylesheet switching and test fixtures. None of them is security-relevant.
📖 AGENTS.md: ✅ LGTM
The AGENTS.md entry matches what the code does.
📋 Code Quality: ✅ LGTM
The leavingAppGroup walk now reads module info with ?. and a ?? [] fallback, the same way the appGroupModules walk does, so buildEnd can't throw on an id that has no module info.
The rest checks out too:
- Stylesheet switching: every navigation path is wired for it, including the error target and no-data navigations.
- Stale navigations: they are still detected after each await.
- Chunking guards: the inlining guards agree with each other across the
optionsandoutputOptionshooks. - Tests: the new behaviour is covered by unit, build and Playwright tests.
⚡ Performance: ✅ LGTM
The new chunking plugins run only during production builds, and their cost grows linearly with the number of modules. They add no file reads or other I/O per module. Their state is reset in buildStart and generateBundle, so it doesn't grow across builds.
📝 Documentation: ✅ LGTM
The README, differences.mdx and the example README match what the code does.
Reviewed commit: f54d92f5
Two cases added to the shared-requests spec, both failing on purpose: - indexes: what _app leaves of a side-effect-free barrel is downloaded once now, but as a file of its own: each page makes one request more than in Next.js, where it stays in the pages' chunks - atlas: the same two pages share rows without CSS and sections with CSS modules, each over 20 kB. They load as two files; Next.js loads one Real Next.js 16.2.7 (webpack) meets both expectations on this fixture.
|
Re-tested f54d92f the same way (large Pages Router app against real Next.js 16 webpack, dev and production, with and without the Cloudflare plugin). Rendering: unchanged, still aligned. 4 of about 16,000 elements differ from Next.js in production on Node, 10 on Workers, 0 and 6 in dev, none about chunking. Workers and Node render identically. Requests on the app
Summed over 17 routes in the browser: Next.js 267 scripts and 78 stylesheets; 823fde4 402 and 193; f54d92f 390 and 193. What moved: the helper that a page and a shared list both use ( What the four expected failures cost The cases now marked Two more reproductions (aa67872) Added to
One thing I could not reproduce in a fixture The heaviest pages of the app still download 3 small modules twice (9 kB). The
I tried that shape with the barrel in the fixture (large module plus list, groups of small files, |
There was a problem hiding this comment.
Superseded by the review of
3b5c6bab.
This review, of aa678729
💬 Approved with comments — One WARNING: the head commit adds two e2e cases that it says fail on purpose, but neither is marked as an expected failure, so the pages-router-prod Playwright project should go red. No production code changed since the last review.
Findings: 1 warning (1 is an inline comment on the diff)
Not opened by the correctness review: 31 changed files it was meant to read
examples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/arrow.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/box.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/ledger.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/person.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/truck.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/unused.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-grid-kit/grid-kit.module.cssexamples/pages-router-complex/__test_packages__/atlas-grid-kit/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/lib/pad.jsexamples/pages-router-complex/lib/workbench/export/csv.tsexamples/pages-router-complex/lib/workbench/format/currency.tsexamples/pages-router-complex/lib/workbench/format/durations.tsexamples/pages-router-complex/lib/workbench/panel.module.cssexamples/pages-router-complex/lib/workbench/reporting/breakdown-table.tsxexamples/pages-router-complex/lib/workbench/reporting/shared-axis.tsexamples/pages-router-complex/lib/workbench/reporting/trend-legend.tsxexamples/pages-router-complex/lib/workbench/status-pill.tsxexamples/pages-router-complex/lib/workbench/summary-strip.tsxexamples/pages-router-complex/lib/workbench/tools/presets.jsonexamples/pages-router-complex/pages/[zone]/workbench/desk.module.cssexamples/pages-router-complex/pages/[zone]/workbench/desk.module.css.d.tsexamples/pages-router-complex/pages/[zone]/workbench/dispatch.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/index.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/inventory.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/ledger.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/media.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/reports.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/roster.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/search.page.tsx
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
🔧 Fix with your agent
Paste the following into your coding agent to investigate and fix these issues.
Fix the following code review issues found in pull request #4726.
Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order
## WARNING (1)
### [Code Quality] The new indexes request-count and atlas cases fail on purpose (commit aa678729) but are not marked as expected failures, so the pages-router-prod Playwright project should fail at this head.
- **File:** tests/e2e/pages-router-prod/shared-requests.spec.ts:226
📋 Code Quality: ⚠️ 1 warning
Two new shared-requests cases fail on purpose but have no test.fail() marker.
Recommendation: 📝 Minor Comments
- [WARNING] The new indexes request-count and atlas cases fail on purpose (commit aa67872) but are not marked as expected failures, so the pages-router-prod Playwright project should fail at this head. (
tests/e2e/pages-router-prod/shared-requests.spec.ts:226)
View full review
Commit aa67872 says both new cases fail on purpose:
- indexes request count: each page makes one request more than in Next.js.
- atlas: the shared board loads as two files where Next.js loads one.
The tests at tests/e2e/pages-router-prod/shared-requests.spec.ts:218-227 and :229-239 end in a plain expect(...) with no test.fail(). The other cases in this file that can't pass yet (lines 140, 158, 171 and 201) take their measurements first and then call test.fail() with the reason next to it. These two should do the same, or land with the change that makes them pass. As written, the required Playwright E2E check should fail on this branch.
The new lib/atlas/* and pages/atlas/* fixtures match what the spec says they test.
✅ All other checks passed
🔒 Security: ✅ LGTM
Since the last review, only test fixtures and an e2e spec changed. No security-relevant changes.
📖 AGENTS.md: ✅ LGTM
The AGENTS.md entry still matches the code.
⚡ Performance: ✅ LGTM
Since the last review, only test fixtures and an e2e spec changed.
📝 Documentation: ✅ LGTM
The README, differences.mdx and the example README still match the code.
Reviewed commit: aa678729
| // makes a request for what `_app` leaves of the barrel. | ||
| const extra = await extraScripts(page, ["/indexes/both", "/indexes/north", "/indexes/south"]); | ||
|
|
||
| expect(extra).toEqual({ "/indexes/both": 2, "/indexes/north": 1, "/indexes/south": 1 }); |
There was a problem hiding this comment.
The new indexes request-count and atlas cases fail on purpose (commit aa67872) but are not marked as expected failures, so the pages-router-prod Playwright project should fail at this head.
Commit aa67872 says this case and the atlas case below (line 238) both fail on purpose: one request more than Next.js per page, and two files instead of one. Neither calls test.fail(), so the required Playwright E2E check goes red. A real regression in this spec would also be hidden behind the known failure. Add test.fail() with the limitation just before the parity assertion in both tests, after the measurements, as the panels/lists/tables/drawer cases at lines 140-201 already do.
…hat reaches 20 kB, with the stylesheets only the group imports
|
Thanks. Here's where the two new cases in aa67872 stand at 3b5c6ba.
This one was vinext's own grouping. A small module that imports a stylesheet stays out of its set's group, so that it gets copied into the pages. When the modules left out of one set's group reach 20 kB together, Rolldown doesn't copy them: it gives them a common chunk of its own for the same pages. That chunk was
On the app: with the
|
|
/bigbonk Please review exact head |
There was a problem hiding this comment.
Superseded by the review of
529bedb7.
This review, of 3b5c6bab
✅ Approved — The only earlier finding, the unmarked failing e2e cases, is fixed at this head. No new issues were found in the code changed since the last review.
Not opened by the correctness review: 31 changed files it was meant to read
examples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/arrow.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/box.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/ledger.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/person.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/truck.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/unused.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-grid-kit/grid-kit.module.cssexamples/pages-router-complex/__test_packages__/atlas-grid-kit/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/lib/pad.jsexamples/pages-router-complex/lib/workbench/export/csv.tsexamples/pages-router-complex/lib/workbench/format/currency.tsexamples/pages-router-complex/lib/workbench/format/durations.tsexamples/pages-router-complex/lib/workbench/panel.module.cssexamples/pages-router-complex/lib/workbench/reporting/breakdown-table.tsxexamples/pages-router-complex/lib/workbench/reporting/shared-axis.tsexamples/pages-router-complex/lib/workbench/reporting/trend-legend.tsxexamples/pages-router-complex/lib/workbench/status-pill.tsxexamples/pages-router-complex/lib/workbench/summary-strip.tsxexamples/pages-router-complex/lib/workbench/tools/presets.jsonexamples/pages-router-complex/pages/[zone]/workbench/desk.module.cssexamples/pages-router-complex/pages/[zone]/workbench/desk.module.css.d.tsexamples/pages-router-complex/pages/[zone]/workbench/dispatch.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/index.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/inventory.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/ledger.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/media.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/reports.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/roster.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/search.page.tsx
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security-relevant issues in the changes.
📖 AGENTS.md: ✅ LGTM
The AGENTS.md entry still matches the code.
📋 Code Quality: ✅ LGTM
The earlier WARNING is fixed:
- The
indexesrequest-count case intests/e2e/pages-router-prod/shared-requests.spec.tsmeasures first, then callstest.fail()just before its parity assertion (line 229). - The
atlascase passes as written after f3670b1, so it needs no marker.
In client-build-config.ts, the new helpers are consistent with how tests/pages-client-chunks.test.ts uses them. The inlining guards match the Rolldown restrictions the description lists.
⚡ Performance: ✅ LGTM
No performance issues in the changes.
📝 Documentation: ✅ LGTM
The README, differences.mdx and the example README still match the code.
Reviewed commit: 3b5c6bab
|
LGTM! |
…he client graph collectUncopiedStylesheets walked every stylesheet's importers up to the entries, which cost 279 ms of the client build on the large Pages Router benchmark (about 800 stylesheets in 4000 modules). The client graph that buildEnd already collects has the same entries for each module.
There was a problem hiding this comment.
Superseded by the review of
a85e1e9c.
This review, of 529bedb7
✅ Approved — No new issues in the code changed since the last review, and the earlier findings are fixed or answered.
Not opened by the correctness review: 31 changed files it was meant to read
examples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/arrow.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/box.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/ledger.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/person.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/truck.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/unused.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-grid-kit/grid-kit.module.cssexamples/pages-router-complex/__test_packages__/atlas-grid-kit/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/lib/pad.jsexamples/pages-router-complex/lib/workbench/export/csv.tsexamples/pages-router-complex/lib/workbench/format/currency.tsexamples/pages-router-complex/lib/workbench/format/durations.tsexamples/pages-router-complex/lib/workbench/panel.module.cssexamples/pages-router-complex/lib/workbench/reporting/breakdown-table.tsxexamples/pages-router-complex/lib/workbench/reporting/shared-axis.tsexamples/pages-router-complex/lib/workbench/reporting/trend-legend.tsxexamples/pages-router-complex/lib/workbench/status-pill.tsxexamples/pages-router-complex/lib/workbench/summary-strip.tsxexamples/pages-router-complex/lib/workbench/tools/presets.jsonexamples/pages-router-complex/pages/[zone]/workbench/desk.module.cssexamples/pages-router-complex/pages/[zone]/workbench/desk.module.css.d.tsexamples/pages-router-complex/pages/[zone]/workbench/dispatch.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/index.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/inventory.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/ledger.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/media.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/reports.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/roster.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/search.page.tsx
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security-relevant issues in the changes:
- Stylesheet hrefs come from the build manifest.
- Attributes are escaped.
- The deployment-ID query adds no new exposure.
📖 AGENTS.md: ✅ LGTM
The AGENTS.md entry still matches the code.
📋 Code Quality: ✅ LGTM
The new and changed helpers in client-build-config.ts are consistent with how tests/pages-client-chunks.test.ts uses them:
collectPagesClientGraphcollectUncopiedStylesheetscollectSharedGroupModules
The plugin clears its per-build state in buildStart, so the SSR build that follows sees empty sets. The test file's conditional expectations on supportsInlineCommonChunks cannot pass without checking anything.
⚡ Performance: ✅ LGTM
Reading the entries that load each stylesheet from the shared client graph removes the importer walk the build ran for every stylesheet.
📝 Documentation: ✅ LGTM
The README, differences.mdx and the example README still match the code.
Reviewed commit: 529bedb7
There was a problem hiding this comment.
✅ Approved — The only change since the last review is the AGENTS.md entry, which matches the code. A re-read of the rest of the pull request found no new issues.
Not opened by the correctness review: 29 changed files it was meant to read
examples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/arrow.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/box.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/ledger.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/person.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/truck.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/glyphs/unused.jsexamples/pages-router-complex/__test_packages__/atlas-glyphs/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-grid-kit/grid-kit.module.cssexamples/pages-router-complex/__test_packages__/atlas-grid-kit/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/index.d.tsexamples/pages-router-complex/__test_packages__/atlas-legacy-format/lib/pad.jsexamples/pages-router-complex/lib/workbench/export/csv.tsexamples/pages-router-complex/lib/workbench/format/currency.tsexamples/pages-router-complex/lib/workbench/format/durations.tsexamples/pages-router-complex/lib/workbench/panel.module.cssexamples/pages-router-complex/lib/workbench/reporting/breakdown-table.tsxexamples/pages-router-complex/lib/workbench/reporting/shared-axis.tsexamples/pages-router-complex/lib/workbench/reporting/trend-legend.tsxexamples/pages-router-complex/lib/workbench/summary-strip.tsxexamples/pages-router-complex/lib/workbench/tools/presets.jsonexamples/pages-router-complex/pages/[zone]/workbench/desk.module.cssexamples/pages-router-complex/pages/[zone]/workbench/desk.module.css.d.tsexamples/pages-router-complex/pages/[zone]/workbench/dispatch.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/index.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/inventory.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/ledger.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/reports.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/roster.page.tsxexamples/pages-router-complex/pages/[zone]/workbench/search.page.tsx
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
Stylesheet hrefs come from the build manifest. Fetched CSS goes into <style> text nodes, not HTML markup. The nonce is read only from noscript[data-n-css]. The new CI matrix entry uses no secrets.
📖 AGENTS.md: ✅ LGTM
The new AGENTS.md entry matches the code: the Pages Router shared groups and the _app imports that stay out of pages-app.
📋 Code Quality: ✅ LGTM
Every client-navigation path passes the page's own stylesheets to the render. The pagesRenderId guard stops a navigation that was cancelled from switching stylesheets. Per-build plugin state is cleared in buildStart and generateBundle, so the SSR build that follows doesn't inherit the groups. The entry-code rewrite keeps the source map aligned. The deployment-ID query is handled the same way in the built asset URL helper, the Flight rows, the Pages stylesheet URLs and the inline-CSS lookup.
⚡ Performance: ✅ LGTM
The build reads the entries that load each stylesheet from the shared client graph, so it no longer walks the importers of every stylesheet.
📝 Documentation: ✅ LGTM
The README, differences.mdx and the example README still match the code.
Reviewed commit: a85e1e9c
|
/bigbonk review for issues Please review exact head |
|
LGTM! |
Pages Router production builds load many more client JS files than Next.js does. On
examples/pages-router-complexa desk page loaded 22–23 files, against 5–6 for Next.js webpack and 10 for Turbopack. There were two causes._app's imports were split into many chunks. A module that_appand some pages both import (next/link's helpers,next/script,next/dynamic, app components) got a shared chunk of its own, even though every page loads_app. That added up to 8 tiny files on every route.vinext:pages-client-chunksnow puts_app's static imports, and what Rolldown finds they use, in onepages-appchunk, short of theframeworkandvinextchunks. Next.js keepspages/_appunsplit for the same reason. Nothing is over-fetched, since every page loads_appanyway._appitself keeps its own chunk, because the client entry imports it and the Pages manifests (CSS order, preloads) look it up by source path. The group starts from_app's direct imports and leaves the rest to Rolldown, so a page-only export of a side-effect-free barrel that_appalso imports stays out of the chunk every page loads. An import that statically leads back to_app, or to a module the client entry loads beyond vinext's first group (instrumentation-client's imports and theirimport()targets), stays in_app's chunk. Rolldown would pull that module into the group too, and the entry would then load the whole group before_app. A page that one of_app's imports imports joins the group, as it joinspages/_appin Next.js._appis also an entry of the client build, as in Next.js. Rolldown orders a chunk's modules (and so its CSS) by visiting the entries before theimport()targets, so pages that sort before_appno longer order what they share with it ahead of_app's own imports, such as a CSS module ahead of_app's global stylesheet.The
pages-appchunk holds_app's stylesheets too, in import order. The SSR-manifest backfill now also lists the stylesheets of the chunks a chunk statically imports, ahead of the chunk's own, so a server bundle without the CSS graph (server built before the client) still links_app's CSS.Small modules shared by different sets of pages each got a tiny common chunk. webpack and Turbopack copy small shared modules into each page instead. With Rolldown 1.2.18+, vinext now turns on
codeSplitting.experimentalInlineCommonChunksat 20 kB, Next.js' webpacksplitChunks.minSize. Rolldown keeps one instance of each copied module and evaluates it only when an importer needs it, so module evaluation stays the same as in Next.js.Modules that the same pages share get a chunk once they reach 20 kB, as webpack's
splitChunksgives them.collectSharedGroupModulesnames apages-shared-Ngroup for each set of pages whose shared modules reach 20 kB together. The group is entries-aware, because vinext decides it from the module graph before tree shaking: Rolldown splits it by the pages that use each part after, and copies a part under 20 kB into them. Rolldown copies a small common chunk into the chunks that import it, not into the pages, so a small module that imports one that no group takes, or a stylesheet, stays out of its set's group and is copied into the pages with what it imports, unless what stays out reaches 20 kB too. A stylesheet that only one group's modules import joins the group.A page downloads each module once. Inlining copies a small common chunk into each chunk that imports it, so a page that loads two of those would download the module twice, and link a stylesheet's rules twice, where the second copy overrides the first chunk's own stylesheet. webpack and Turbopack give a page one copy of each module.
collectDoublyCopiedModulesfinds the chunks Rolldown would copy into two chunks that load together (both loaded by one page, or one of them with every page through_app), and those keep a file. So do the small modules of a shared group that two of the group's modules import (collectSharedGroupDependencies), since tree shaking could leave them a part of their own that Rolldown would copy into both.Stylesheets follow webpack too. A copied CSS module joins each importing page's stylesheet, so small CSS that pages share no longer gets a tiny stylesheet of its own. webpack applies
minSizeto the CSS of each set of pages that share it, but Rolldown's size only counts the JavaScript a stylesheet compiles to. Sovinext:pages-client-stylesheet-sizesrecords each stylesheet's compiled size, and a chunk isn't copied when it holds stylesheets that the same set of pages loads with 20 kB of CSS together. That CSS keeps one stylesheet, as in webpack. Turbopack merges CSS further, into one large stylesheet that most pages load. Nor is a chunk copied when it holds CSS that a page shares with anext/dynamictarget. webpack leaves out of a page's dynamic chunk what the page already has, but Rolldown has one chunk perimport()target, so a copy there would link the CSS again after the page's own.Client navigations now switch page stylesheets as Next.js does. With small shared CSS copied into page stylesheets, an earlier page's copy would keep applying after a client navigation, before or after the new page's rules. Next.js's webpack client switches page stylesheets on navigation, and vinext now ports that. The client entry lists each route's own stylesheets: the ones its page loads, without
_app's and without those that other dynamic imports load. A navigation loads them into<style>tags turned off withmedia="x". As the page commits, before its layout effects run, only its tags are on, in its order, after<noscript data-n-css>, and the server's<link>s for page stylesheets go. The links of stylesheets that anext/dynamicimport also loads stay, as with Next.js's dynamic CSS manifest. Those stylesheets are linked ahead of the marker, as on a full load. Vite's preload helper then finds the link when anext/dynamicimport loads one later, rather than adding another after the page's own CSS. A link it already added on an earlier page moves ahead of the marker. On a later page that doesn't load that stylesheet, the link, or the server's link to it, goes back after the page's own CSS, into the place Vite added it among the dynamic imports' other stylesheets. So anext/dynamiccomponent's CSS still wins there, as with Next.js's webpack client, which loads it from a stylesheet of its own. For a page that lists the stylesheet after anext/dynamicimport on an earlier page loaded it, vinext matches Turbopack, where webpack lets that earlier link override the page's own CSS. Turbopack never unloads page CSS and its prefetches link other pages' stylesheets, so in a few navigation orders it lets page CSS beat a dynamic component's CSS where webpack and vinext don't. If a stylesheet fails to load, the navigation becomes a full page load, as in Next.js. Page loaders no longer have Vite preload page stylesheets, so prefetching a page doesn't apply its CSS to the current page; the prefetch loads the stylesheet text instead. With a relativebase, theurl()s in that text resolve against the stylesheet, as they would from its<link>.Stylesheets loaded from JavaScript now keep the deployment ID query. Without it, Vite's preload helper didn't recognise the server's link and appended a second copy after the page's CSS, which reordered the cascade on main whenever
deploymentIdwas set. App Router CSS URLs get the query too, as in Next.js, and so do the stylesheets that client references' Flight rows name, so the browser finds them already linked.experimental.inlineCsslooks them up without it.In dev, Vite adopts the server's Pages stylesheet links. The server's
<link>s now carrydata-vite-dev-id, the id that Vite's CSS transform passes toupdateStyle(), taken from the import resolution the dev manifest already does. Vite's client then adopts the link instead of injecting the stylesheet again in module execution order. With@cloudflare/vite-plugin, it injected_app's global CSS and a component's CSS module again, and the global rules ended up overriding the module's.I tried merging small shared modules into one chunk and rejected it: a page would then evaluate modules it never imports.
Inlining is skipped on older Rolldown and with options Rolldown rejects in combination with it:
strictExecutionOrder: false, non-ESM output,preserveModules, strict entry signatures,onDemandWrapping. It's also skipped when the output already configures it. The plugin checks the input options as they stand after every plugin'soptionshook. It'senforce: "post", so it also sees the output after every normal-order plugin'soutputOptionshook.disableNextLikeChunking: truenow turns both changes off. Hybrid App + Pages builds and library builds keep their current chunking, and so does the plain Pages SSR build, which inherits the client output options.Results
JS files each route loads on
examples/pages-router-complex(production build: the scripts and module preloads in its HTML). Next.js also loads 3 manifest or polyfill files per route on top of these./,/journal,/workbenchAgainst webpack, one extra file per route is
_app's own chunk. The other extra files are:import()of a module that's also inlined elsewhere;next/navigationloads.Each route downloads 2.9–5.9 kB more gzipped JS than on main (2–4%, from 136–159 kB). Inlining makes Rolldown use strict execution order, which wraps each module in a lazy init function, including on routes that inline nothing. Rolldown rejects inlining with strict execution order turned off and with
onDemandWrapping.Fixture
examples/pages-router-complexgains workbench desks that give the client build a varied chunk graph:next/dynamicwith and without SSR,React.lazy, and on-demandimport();next/image,next/script,next/formandnext/navigation.tests/e2e/pages-router-complex/chunk-scenarios.spec.tschecks each scenario still loads and hydrates. One test checks that a module copied into five page chunks evaluates once across client navigations, and not on a page that doesn't import it.Tests
tests/pages-client-chunks.test.tsbuilds the newtests/fixtures/pages-client-chunksclient and checks several things:_appkeeps its own chunk, which imports the one chunk holding a module_appshares with a page, even when a module_appimports imports_appback, and the client entry doesn't load that chunk when_appshares a module with instrumentation-client; an import that usesnext/linkstill joins it;_appuses joins that chunk, and the rest of that barrel is copied into the pages that use it;_app's imports alone;disableNextLikeChunkingleaves all of this to the bundler;onDemandWrappingon from itsoptionshook gets a working build with no inlining.It also unit-tests picking
_app's imports (including leaving out imports that lead back to_appor to a module the client entry loads, but not ones that only share vinext's first-group helpers with it), grouping stylesheets by the entries that load them, the shared groups, the chunks that would be copied twice into one page, the Rolldown version check and the inlining guards.tests/asset-prefix.test.tschecks that withdeploymentIdset, client reference Flight rows name stylesheets exactly as the server links them.tests/build-optimization.test.tschecks that the SSR-manifest backfill lists the stylesheets of statically imported chunks, deepest first and ahead of the chunk's own.tests/pages-css-order.test.tsnow compares cascade positions across the linked stylesheets, since_app's CSS and a component CSS module it shares with a page now share one stylesheet, in import order.tests/e2e/pages-router-prod/css-navigation.spec.tsbuildstests/fixtures/pages-css-navigation. It checks computed colours on full loads, over a 22-step client navigation tour (including a page that imports a small CSS module after anext/dynamiccomponent loaded it on another page), on back and forward, and when a page loads anext/dynamiccomponent on click after a client navigation, and checks that only the page's<style>tags are on, in order, after the marker. Real Next.js 16.2.7 gives the same colours on this fixture with both webpack and Turbopack, except on that navigation, where webpack applies the small module's rules over the page's own and Turbopack doesn't; vinext matches Turbopack.tests/pages-page-stylesheets.test.tsunit-tests the route stylesheet lists and the preload stripping.The tester's request-count specs compare what each page downloads with real Next.js 16.2.7 (webpack), which meets every expectation on their fixtures:
tests/e2e/pages-router-prod/client-chunk-requests.spec.ts(tests/fixtures/pages-client-chunk-requests):_app's imports load as one chunk, and a small module or CSS module that two of a page's shared chunks use loads once, its CSS linked ahead of both;shared-group-requests.spec.ts(tests/fixtures/pages-shared-group-requests): a small component that two shared groups of small files use costs no request of its own, and the page links one stylesheet;shared-requests.spec.ts(tests/fixtures/pages-shared-requests): shared lists of small components with CSS modules, a helper that a page and a shared list both use, anext/dynamiccomponent, and a side-effect-free barrel that_appimports from. Five of its cases aretest.fail()at their parity assertion: Vite and Rolldown can't meet them (see Known limitations).tests/e2e/pages-router-prod/app-css-order.spec.ts(tests/fixtures/pages-app-css-order) checks that_app's global stylesheet stays ahead of a CSS module that a page sorting before_appalso imports, andapp-imports-page.spec.ts(tests/fixtures/pages-app-imports-page) that_app's imports load with_appwhen one of them imports a page.tests/e2e/cloudflare-pages-router-dev/css-order.spec.ts(tests/fixtures/cf-pages-dev-css-order) checks that Vite adopts the Worker's initial Pages stylesheets instead of injecting them again, and that a component's CSS module still wins over_app's global stylesheet after hydration.chunk-scenarios.spec.tsruns in CI againstvp devand, as the newpages-router-complex-prodproject, against a production build.Performance
Measured locally on an Apple M4 Pro: main at the merge base
124aa20against this branch at529bedb, in alternating rounds. The browser figures come from Playwright's Chromium with 4× CPU throttling and no cache, as medians of 8 loads per round, against local servers. The two apps areexamples/pages-router-complex(served byvp previewon workerd) andbenchmarks/pages-large(30 pages over 40 barrel packages of about 100 tiny modules each, served byvinext starton Node).Dev. The chunking only applies to builds; dev gets the stylesheet shim and the
data-vite-dev-idattributes.vp devcold start to the first/response, pages-large, 11 pairs: medians 8.37 s on main and 8.70 s here. The median paired difference is −66 ms, and pairs ranged from −2.0 s to +4.0 s, so this is noise (load average 5–6).Build.
buildEndanalysis.529bedbreads each stylesheet's entries from the client graph instead of walking up from each stylesheet, which cut it from 463 ms to 143 ms. The rest of the gap is Rolldown rendering and minifying the larger output.Server. Rendering is unchanged:
/with either;Browser, pages-router-complex.
/takes 114–117 ms with either, ledger 139–144 ms against 140–141 ms./to roster takes 49–50 ms against 57 ms, with 2 JS requests instead of 10./, ~635 ms for ledger). Client navigation from/to roster drops from 300–311 ms to 236–239 ms (−22%), and from ledger to roster from 260–262 ms to 244–254 ms.Browser, pages-large. Each page loads 7 JS files instead of 13 and 1 stylesheet instead of 5 (Next.js webpack: 5 and 1), but 320 kB of gzipped JS instead of 183 kB (Next.js webpack: 204 kB).
This is the strict execution order wrapper from Results. Its cost grows with the number of modules, and pages-large has about 4000 tiny ones. Like Next.js, this PR puts what every page shares in the chunk that loads with
_app, so nothing is over-fetched, but with each module wrapped, thepages-appchunk is 217 kB gzipped where Next.js's_appchunk with the same modules is 97 kB. See Known limitations.The CI benchmark job (alternating rounds on one runner) found no regressions on
a85e1e9: all 7 scenarios were within ±1.5%, including the large Pages Router dev cold start (−0.1%) and the production build (−0.2%). Its client bundle scenario builds an App Router app, so it doesn't cover this.Known limitations
These come from Vite and Rolldown, so this PR leaves them rather than working around them. The five
test.fail()cases inshared-requests.spec.tscover the first three.experimentalInlineCommonChunkscopies a small chunk into the chunks that import it, not into the pages. A small module that two shared chunks over 20 kB import would download twice on a page that loads both, so it keeps a chunk of its own, where Next.js puts it in the pages' chunks. This covers a small component or helper that two shared lists use, and the modules of a side-effect-free barrel that_appimports from without using them when two large shared chunks use them.import()target. webpack builds anext/dynamiccomponent's chunk for each page and leaves out what the page has. So a small component with a CSS module that pages and anext/dynamiccomponent both use keeps a chunk, since a copy in the dynamic chunk would link its CSS twice.benchmarks/pages-large, with about 4000 tiny modules, it's 75% more JS and +60 ms of hydration at 4× CPU throttling (see Performance).