[system][styleFunctionSx] Fix theme mutation when using responsive typography shorthand in sx#48266
Open
tomups wants to merge 1 commit intomui:masterfrom
Open
[system][styleFunctionSx] Fix theme mutation when using responsive typography shorthand in sx#48266tomups wants to merge 1 commit intomui:masterfrom
tomups wants to merge 1 commit intomui:masterfrom
Conversation
…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.
Netlify deploy previewhttps://deploy-preview-48266--material-ui.netlify.app/ Bundle size report
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #48265
setThemeValueinstyleFunctionSx.jsassignscss[mediaKey] = finalValuewherefinalValueis a theme typography variant object returned by reference fromgetPath. 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 intotheme.typography.<variant>.For example, after rendering
<Box sx={{ typography: { md: 'h4' }, width: { md: '80%' } }}>,theme.typography.h4permanently containswidth: '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 usingmerge(css[mediaKey], finalValue)instead of the direct assignment.Regression from #44254.