fix(build): correct CSS ordering for global-not-found (#1549)#1858
Conversation
Adds a production-build regression test for #1549: builds the global-not-found-css-order fixture, serves it via the Vite preview server, and asserts the route-miss 404 document serves global-not-found's own CSS (red wins) without leaking the root layout's stylesheet (green), while matched routes still serve the layout's CSS. Verified the test fails without the framework-chunk split in client-build-config.ts (the 404 leaks the layout's green) and passes with it.
|
/bigbonk review for issues |
Review: fix(build): correct CSS ordering for global-not-found (#1549)I reviewed the fix end-to-end: verified the architecture, ran the new test, the broader build-optimization suite, the existing dev-server One non-blocking finding worth addressing before merge, plus a couple of minor notes. 1. (Should fix) New code uses the deprecated
|
|
Review posted to PR #1858. SummaryThe fix is correct and well-targeted. It isolates React + the RSC flight runtime into a dedicated CSS-free Findings I posted:
No correctness or dev/prod parity bugs found — the regex correctly avoids over-matching ( |
|
/bigbonk review for issues |
commit: |
|
|
The |
|
/bigbonk review for issues |
|
/bigbonk review for issues |
|
@james-elicx Bonk workflow was cancelled. View workflow run · To retry, trigger Bonk again. |
…it tests Address bonk review on #1858 (issue #1549): - Replace the deprecated rolldown `advancedChunks` output config with the non-deprecated `codeSplitting` form for Vite 8+, mirroring the client build. Stops the per-prod-build deprecation warning. - Derive both RSC_FRAMEWORK_CHUNK_TEST (regex) and isRscFrameworkModule (predicate) from a single FRAMEWORK_PACKAGES list so they can't drift. - Add focused unit tests for createRscFrameworkChunkOutputConfig (both the Vite 7 manualChunks and Vite 8+ codeSplitting branches) and for the framework package matching (matches react/react-dom/scheduler/ react-server-dom-webpack, excludes react-icons / @react-aria/*).
|
/bigbonk review for issues |
There was a problem hiding this comment.
Re-review: fix(build): correct CSS ordering for global-not-found (#1549)
The latest commit (ab1a7ea) addresses all three findings from the prior review round. The fix is correct, well-targeted, and ready to merge.
Prior findings — all resolved
- (was Should fix)
advancedChunks→codeSplitting—createRscFrameworkChunkOutputConfignow emitscodeSplitting.groupsfor Vite 8+ (client-build-config.ts:209-216), matching the client build's non-deprecated form. No more deprecation warning on every prod build. ✅ - (was Minor) Missing focused unit test — both branches are now covered:
describe("createRscFrameworkChunkOutputConfig")asserts the Vite 7manualChunksshape and the Vite 8/9codeSplittingshape (and explicitly that it is notadvancedChunks/manualChunks). ✅ - (was Nit) Two sources of truth —
RSC_FRAMEWORK_CHUNK_TESTandisRscFrameworkModulenow both derive from a singleFRAMEWORK_PACKAGESconst (client-build-config.ts:185), and adescribe("RSC framework package matching")block verifies both stay in agreement (react/react-dom/scheduler/react-server-dom-webpack match;react-icons,@react-aria/*, and pnpm paths handled correctly). ✅
What I verified on this revision
tests/build-optimization.test.ts— newcreateRscFrameworkChunkOutputConfig(2/2) andRSC framework package matching(2/2) suites pass.tests/app-router-global-not-found-css-order.test.ts— passes (2/2):/keeps the layout'sgreen,/does-not-existresolves tobackground-color:redwith nogreenleak.tests/nextjs-compat/global-not-found.test.ts(5) +tests/entry-templates.test.ts(25) — pass, no regressions.vp checkonclient-build-config.tsandindex.ts— clean (format, lint, types). ThecodeSplitting.groups[].test: RegExpshape type-checks against the Vite 8 / rolldown types.
Correctness / parity checks
- No
outputclobbering: thersc:environment build block (index.ts:2082-2095) previously set onlyinput; addingoutputdoes not overwrite any pre-existing RSC output config in that object. End-to-end build + preview confirms no plugin-level conflict. - Dev/prod + Cloudflare parity: the framework-chunk split is applied to the
rscenvironment unconditionally — thehasCloudflarePlugin || hasNitroPluginguard only gates theresolve.external/noExternalblock, notbuild.output. So both the standard App Router prod build and the Cloudflare Workers build inherit the fix. No separate worker build path needs a duplicate fix. - No
minSizeon the RSC framework group is intentional and correct: omitting it guarantees the split happens regardless of chunk size, which is exactly what the CSS-isolation goal requires (React always exceeds any threshold anyway). - Regex robustness:
[\\\\/]node_modules[\\\\/](...)[\\\\/]correctly matches the innernode_modules/react/segment of pnpm paths and avoids over-matchingreact-icons/@react-aria/*.
LGTM.
|
Review posted to PR #1858. SummaryI re-reviewed PR #1858 at its current head ( Prior findings — all resolved:
What I verified:
Correctness/parity checks (no new issues found):
LGTM — no blocking issues. |
Finishes #1549 (initial work in #1654).
Problem
For
app/global-not-found.tsx(the Next.js 16 route-miss 404 document that replaces the root layout), the production RSC build colocated React into the RSC entry chunk — which also carries the root layout's CSS. Becauseglobal-not-found.tsximports that entry chunk for its React runtime helpers, it inherited the root layout's stylesheet in itsserverResourcesmetadata. The 404 document then linked the layout's CSS last, so the layout's rules won the cascade over global-not-found's own styles.Fix
createRscFrameworkChunkOutputConfig(inpackages/vinext/src/build/client-build-config.ts) isolates React (and thereact-server-dom-webpackflight runtime) into a dedicated, CSS-freeframeworkchunk in the RSC server build. global-not-found now imports that chunk for its React helpers instead of the layout-bearing entry chunk, so it no longer inherits the layout's CSS. The matcher mirrors the existing client-buildframeworkchunk and returns the bundler-correct shape (advancedChunksfor Vite 8+ / rolldown,manualChunksfor Vite 7 / Rollup).Test
Adds
tests/app-router-global-not-found-css-order.test.ts, a production-build regression test (ported from upstreamtest/e2e/app-dir/initial-css-order— theglobal-not-foundcase):global-not-found-css-orderfixture and serves it via the Vite preview server./): the root layout's CSS is served (green wins); global-not-found's CSS is absent./does-not-exist): only global-not-found's CSS is served — red wins (gnf-b imported last) and the layout'sgreendoes not leak in.Verified the test fails without the framework-chunk split (the 404 leaks the layout's
green) and passes with it.Closes #1549