Skip to content

[system] Fix theme mutation when using responsive typography shorthand in sx#48266

Merged
mj12albert merged 2 commits into
mui:masterfrom
tomups:fix/sx-typography-theme-mutation
Apr 13, 2026
Merged

[system] Fix theme mutation when using responsive typography shorthand in sx#48266
mj12albert merged 2 commits into
mui:masterfrom
tomups:fix/sx-typography-theme-mutation

Conversation

@tomups
Copy link
Copy Markdown
Contributor

@tomups tomups commented Apr 12, 2026

Summary

Fixes #48265

setThemeValue in styleFunctionSx.js assigns css[mediaKey] = finalValue where finalValue is a theme typography variant object returned by reference from getPath. This replaces the breakpoint's CSS accumulator with the live theme object, so subsequent responsive sx keys targeting the same breakpoint write their CSS properties directly into theme.typography.<variant>.

For example, after rendering <Box sx={{ typography: { md: 'h4' }, width: { md: '80%' } }}>, theme.typography.h4 permanently contains width: '80%', affecting every component using that variant.

The non-responsive path already uses merge(css, finalValue) which copies properties without creating a reference. This PR makes the responsive path consistent by using merge(css[mediaKey], finalValue) instead of the direct assignment.

Regression from #44254.

…pography shorthand in sx

The responsive branch of setThemeValue assigns `css[mediaKey] = finalValue`
where finalValue is a reference to a theme.typography variant object returned
by getPath. This replaces the breakpoint's CSS accumulator with the live
theme object, so subsequent responsive sx keys targeting the same breakpoint
write their CSS properties directly into theme.typography.

Use merge() instead, consistent with the non-responsive path on the next line.
@mui-bot
Copy link
Copy Markdown

mui-bot commented Apr 12, 2026

Netlify deploy preview

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

Bundle size report

Bundle Parsed size Gzip size
@mui/material ▼-2B(0.00%) 0B(0.00%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/system ▼-2B(0.00%) 🔺+1B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against f060658

@mj12albert mj12albert added the type: bug It doesn't behave as expected. label Apr 12, 2026
@mj12albert mj12albert changed the title [system][styleFunctionSx] Fix theme mutation when using responsive typography shorthand in sx [system] Fix theme mutation when using responsive typography shorthand in sx Apr 12, 2026
@mj12albert mj12albert merged commit 3163063 into mui:master Apr 13, 2026
20 checks passed
@mj12albert
Copy link
Copy Markdown
Member

Thanks for the PR @tomups

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

Labels

type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[system] sx typography shorthand with responsive values mutates theme.typography objects

3 participants