Skip to content

experimental.inlineCss: stylesheet duplicated twice in the flight payload — _full.segment.rsc carries the CSS text 2x (3x total per prerendered page) #98079

Description

@TulmansMeubelen

Link to the code that reproduces this issue

https://github.com/TulmansMeubelen/next-inlinecss-flight-duplication-repro

To Reproduce

  1. npm install
  2. npm run build (next build --turbopack)
  3. node count.mjs — counts occurrences of the CSS marker (@layer properties) in the build artifacts

The repro is intentionally tiny: a root layout importing one global stylesheet, one app/[locale]/page.tsx with generateStaticParams, and experimental: { inlineCss: true }.

Current vs. Expected behavior

Current (both 16.3.1 and 16.4.0-canary.12):

artifact copies of the CSS text
.next/server/app/nl.html 3 (1 <style> + 2 flight rows)
.next/server/app/nl.rsc 2
.next/server/app/nl.segments/_full.segment.rsc 2
.next/server/app/nl.segments/_index.segment.rsc 1
every other segment file 0

The two flight copies are byte-identical T-rows, each referenced by its own hoistable style element row (["$","style","1",{"precedence":"next","href":"<chunk>.css","children":"$<id>"}]). Both land in the first flushes of the stream. Since the individual segments together only carry one copy, the second copy appears when the full flight (_full.segment.rsc) is assembled — the assembly re-serializes the hoistable stylesheet instead of reusing the already-emitted row.

Expected: at most one copy of the CSS text in the flight payload — the inlineCss docs describe exactly one RSC-payload copy as the known trade-off ("Styles are duplicated during initial page load - once within <style> tags for SSR and once in the RSC payload"), i.e. 2 copies per document, not 3.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 32679
  Available CPU cores: 16
Binaries:
  Node: 24.11.1
  npm: 11.6.2
Relevant Packages:
  next: 16.4.0-canary.12 (also reproduced on 16.3.1)
  react: 19.2.8
  react-dom: 19.2.8
  typescript: 7.0.2

Which area(s) are affected? (Select all that apply)

CSS, Turbopack, Runtime

Additional context

On a real Tailwind application the inlined stylesheet is large (ours is 249 KB), so the extra flight copy is expensive: every prerendered/ISR-written HTML document carries ~500 KB of flight CSS on top of the 255 KB <style> block. On Vercel this roughly triples ISR write units and fast origin transfer for HTML documents (we measured a content page at 1,174 KB with the flag vs 415 KB without; the third copy alone is ~250 KB per page). Deduplicating the flight copy would remove ~21% of every prerendered page at no functional cost.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CSSRelated to CSS.RuntimeRelated to Node.js or Edge Runtime with Next.js.TurbopackRelated to Turbopack with Next.js.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions