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

Experimental.InlineCss Duplicates The Global Stylesheet Three Times Per Prerendered Page Instead Of The Expected Two

With experimental.inlineCss enabled, the same global CSS text appears three times in prerendered HTML documents: once as a <style> tag and twice in the RSC flight payload. The full flight segment (_full.segment.rsc) re-serializes the hoistable stylesheet instead of reusing the already-emitted row, causing roughly 21% larger prerendered pages and unnecessary ISR write units.

highConfidence 72%Next.jsAffected V16.3.1Affected V16.4.0-Canary.12

Origin Analysis

When assembling the full flight payload (_full.segment.rsc), Next.js fails to deduplicate hoistable stylesheet rows. The leaf segment RSC already contains the global CSS; during full-tree render, the same hoistable style row is emitted again, producing two identical style rows and two identical CSS text rows.
1. Clone the repro repository: https://github.com/TulmansMeubelen/next-inlinecss-flight-duplication-repro 2. Run `npm install` 3. Run `npm run build` (this runs `next build --turbopack`) 4. Run `node count.mjs` to count occurrences of the CSS marker `@layer properties` in the build artifacts. Observe that `nl.html` contains 3 copies, and both `nl.rsc` and `nl.segments/_full.segment.rsc` contain 2 copies.

Fixing Code Block

Edge Case Audit

This hotfix relies on the current structure of RSC flight rows and the exact format of hoistable style elements (`["$","style",...]`). Future changes to Next.js internal row serialization or CSS handling may break the deduplication logic, potentially leaving orphaned rows or removing non-CSS data. The implementation processes the entire payload as a string, which is acceptable for static generation but may increase memory consumption for very large applications. Test thoroughly with Tailwind and other CSS-in-JS setups before deploying. Rollback: remove the dedupe call and revert to the original payload generation; no changes are made to SSR `<style>` generation, so HTML output remains unaffected.

Ecosystem Topology