Skip to content

[InitColorSchemeScript] Server-render in tests for React 19.3#48604

Open
Janpot wants to merge 1 commit into
mui:masterfrom
Janpot:fix/init-color-scheme-render-to-string
Open

[InitColorSchemeScript] Server-render in tests for React 19.3#48604
Janpot wants to merge 1 commit into
mui:masterfrom
Janpot:fix/init-color-scheme-render-to-string

Conversation

@Janpot
Copy link
Copy Markdown
Member

@Janpot Janpot commented Jun 1, 2026

The nightly-cron react@next jobs (test_unit-react@next, test_browser-react@next) fail on InitColorSchemeScript:

Encountered a script tag while rendering React component. Scripts inside React components are never executed when rendering on the client. Consider using template tag instead.

This is a new dev-only error in React 19.3 (react-dom@19.3.0-canary), emitted when a <script> is created during a fresh client mount. It does not fire during SSR or hydration (React adopts the existing node), so it never triggers in documented usage — InitColorSchemeScript is only rendered server-side (Next.js _document or the App Router root layout). The only thing client-mounting it is the test suite (createRenderer().render), where the script is also a non-executing no-op.

The fix renders the component the way it's actually used: swap render → the existing renderToString helper. No component/runtime changes — InitColorSchemeScript stays hook-free with zero client runtime.

Verified green under react@next (19.3.0-canary-d5736f09) and pinned React, in both the node and chromium environments.

@code-infra-dashboard
Copy link
Copy Markdown

Deploy preview

https://deploy-preview-48604--material-ui.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/material 0B(0.00%) 0B(0.00%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@Janpot Janpot added the scope: code-infra Involves the code-infra product (https://www.notion.so/mui-org/5562c14178aa42af97bc1fa5114000cd). label Jun 1, 2026
@Janpot Janpot requested a review from siriwatknp June 1, 2026 14:27
@mj12albert
Copy link
Copy Markdown
Member

#48595 is related, so it's React 19.3 and not Next.js 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: code-infra Involves the code-infra product (https://www.notion.so/mui-org/5562c14178aa42af97bc1fa5114000cd).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants