AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Experimental.InlineCss Duplicates The Full CSS Bundle Into Every RSC/Segment Payload (Standalone Build-Output Bloat)

With output: 'standalone' and experimental.inlineCss enabled, the entire CSS bundle is inlined into each page's initial HTML and additionally serialized into page.rsc and each segment .rsc payload, causing massive build output bloat (e.g., 205 MB duplication on a 700-page site).

highConfidence 85%Next.jsAffected V16.3.0-Canary.66

Origin Analysis

The experimental.inlineCss implementation inlines CSS into HTML but does not exclude CSS modules from the Flight/RSC serialization. Server-side CSS imports are treated as regular JavaScript modules that get embedded in Flight payloads, and each segment rebuilds the same CSS, leading to O(pages × CSS_size × segments) duplication.
1. Create a minimal App Router app with output: 'standalone', experimental.inlineCss: true, a global stylesheet (~155 KB) imported in root layout, and a dynamic route with generateStaticParams (e.g., 60 pages). 2. Run `npm install` and `npm run build`. 3. Inspect `.next/standalone/.next/server/app`: use `grep -rl '\\.u1000{'` to count files containing CSS; observe the CSS marker appears in .html, page.rsc, and each .segments/*.segment.rsc. 4. Note the total size (e.g., 69 MB for 60 pages) is much larger than expected.

Fixing Code Block

Edge Case Audit

This is a speculative patch and should be tested thoroughly. Risks include: (1) the global registry may cause memory leaks or race conditions in concurrent builds; (2) CSS order may be affected if multiple CSS files are imported in different components; (3) client-side navigation might not reapply styles if the HTML is not properly inlined for the initial load. Rollback: remove the patch and either disable experimental.inlineCss or revert to a previous Next.js version. Test with both PPR and non-PPR, CSS in nested layouts, and hot reload.

Ecosystem Topology