Duplicated script tags when using the new React 19 style
tag
#75885
-
Link to the code that reproduces this issuehttps://github.com/brijeshb42/nextjs-inline-style-tag To ReproduceNext.js repro - https://github.com/brijeshb42/nextjs-inline-style-tag
Current vs. Expected behaviorCurrent Behavior: The HTML size keeps on increasing as the usage of a component that renders inline Expected Behavior: The HTML size should not increase (as significantly) with increase in the repetitive usage of the same component that renders the For the same content, html size for Next.js was 131kB and 97.3kB for Tanstack start (when rendering 1000 Button components). Similary, when rendering 20k
Provide environment informationNode.js v20.17.0
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6031
Available memory (MB): 36864
Available CPU cores: 14
Binaries:
Node: 20.17.0
npm: 11.0.0
Yarn: 1.22.22
pnpm: N/A
Relevant Packages:
next: 15.2.0-canary.40 // Latest available version is detected (15.2.0-canary.40).
eslint-config-next: N/A
react: 19.0.0
react-dom: 19.0.0
typescript: 5.7.3
Next.js Config:
output: export Which area(s) are affected? (Select all that apply)CSS, Payload Size Which stage(s) are affected? (Select all that apply)next dev (local), next build (local), next start (local) Additional contextWe (team at @mui) were exploring a styling engine for one of our component libraries and we were trying to use the new <style> tags introduced in React 19 to render css without users requiring to import the CSS. This will be a blocker for us on deciding to use inline style tags for css given the popularity of Next.js |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@brijeshb42 Thank you for submitting an issue! Taking a look— Edit: writing up a response— |
Beta Was this translation helpful? Give feedback.
The reason for the duplicated <script> tags is explained thoroughly here → #42170 (comment) (tl;dr, it's because RSC).
Today, the React behavior that handles the ReactDOM.preload style API calls (preloading, hoisting, and deduping) does not apply for elements. This behavior only applies for ReactDOM.preload style API calls, and unfortunately React does not have a similar imperative API for inlined style rules. This isn't necessarily intentional—the primary element-based use case is to have an external stylesheet, which generally isn't unbounded in size, whereas inline style rules can be. It may be possible to extend this React behavior to elements in the future.
What you can do here is se…