Skip to content

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

Open
tomups wants to merge 1 commit intomui:masterfrom
tomups:fix/sx-typography-theme-mutation
Open

[system][styleFunctionSx] Fix theme mutation when using responsive typography shorthand in sx#48266
tomups wants to merge 1 commit intomui:masterfrom
tomups:fix/sx-typography-theme-mutation

Conversation

@tomups
Copy link
Copy Markdown

@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 a8789bb

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

Labels

None yet

2 participants