Skip to content

[system] Resolve InitColorSchemeScript %s placeholder at build time - #49113

Draft
Janpot wants to merge 1 commit into
mui:masterfrom
Janpot:refactor-init-color-scheme-placeholders
Draft

[system] Resolve InitColorSchemeScript %s placeholder at build time#49113
Janpot wants to merge 1 commit into
mui:masterfrom
Janpot:refactor-init-color-scheme-placeholders

Conversation

@Janpot

@Janpot Janpot commented Sep 8, 2026

Copy link
Copy Markdown
Member

Resolve the %s placeholder at build time instead of shipping it into the browser: 'mode-%s'.replace('%s', colorScheme) becomes "mode-" + colorScheme. No behavior change for any documented attribute shape.

The intended benefit is for what comes next: every static segment now flows through a single serialization point, so once #49091 lands (it adds the escaping helper for the storage keys / scheme defaults), applying that same escaping to the attribute/selector parts is a one-line swap rather than reworking the runtime .replace.

Also fixes a latent bug where a class-form attribute (.mode-%s) additionally emitted an invalid setAttribute('.mode-%s', …) that threw on every render (swallowed by the inline try/catch).

@code-infra-dashboard

code-infra-dashboard Bot commented Sep 8, 2026

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-49113--material-ui.netlify.app/
QR code for https://deploy-preview-49113--material-ui.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+128B(+0.02%) 🔺+65B(+0.04%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 🔺+128B(+0.18%) 🔺+68B(+0.28%)
@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 force-pushed the refactor-init-color-scheme-placeholders branch from ecad100 to 30dbb06 Compare September 8, 2026 13:36
@Janpot Janpot added the security Pull requests that address a security vulnerability. label Sep 8, 2026
buildInitColorSchemeScript emitted `'mode-%s'.replace('%s', colorScheme)`
into the inline script and substituted the scheme at runtime in the
browser. Parse the template once at build time instead and emit plain
string concatenation (`"mode-" + colorScheme`), so the `%s` placeholder
and the runtime `.replace` no longer reach the generated script.

Also fixes a latent bug where a class-form attribute (e.g. `.mode-%s`)
additionally emitted an invalid `setAttribute('.mode-%s', ...)` call that
threw on every render (swallowed by the inline try/catch).
@Janpot
Janpot force-pushed the refactor-init-color-scheme-placeholders branch from 30dbb06 to 5fb96f2 Compare September 9, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security Pull requests that address a security vulnerability.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant