Skip to content

[styled-engine] Prevent enableCssLayer styles from being overridden by unlayered styles#48603

Open
Janpot wants to merge 3 commits into
mui:masterfrom
Janpot:styled-engine/dedicated-cache-key
Open

[styled-engine] Prevent enableCssLayer styles from being overridden by unlayered styles#48603
Janpot wants to merge 3 commits into
mui:masterfrom
Janpot:styled-engine/dedicated-cache-key

Conversation

@Janpot
Copy link
Copy Markdown
Member

@Janpot Janpot commented Jun 1, 2026

Summary

This was showing up in the visual regression tests after #48575, depending on when the injectFirst fixture runs.

When enableCssLayer is set, StyledEngineProvider wraps MUI's styles in @layer mui but keeps emotion's default cache key css - the same key used by the default and injectFirst caches, which insert unlayered. Since the generated class name is ${key}-${hash}, the same style produces the same class name in both the layered and the unlayered caches. An unlayered rule outranks every cascade layer, so whenever a style ends up inserted both unlayered (default / injectFirst) and layered, the unlayered copy silently overrides MUI's own layered style.

@code-infra-dashboard
Copy link
Copy Markdown

code-infra-dashboard Bot commented Jun 1, 2026

Deploy preview

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

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+8B(0.00%) 🔺+8B(+0.01%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 🔺+8B(+0.01%) 🔺+5B(+0.02%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes


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

@zannager zannager added the package: styled-engine Specific to @mui/styled-engine label Jun 1, 2026
@zannager zannager requested a review from siriwatknp June 1, 2026 12:38
@Janpot Janpot force-pushed the styled-engine/dedicated-cache-key branch 2 times, most recently from 8ecd8ba to 99c77f9 Compare June 1, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: styled-engine Specific to @mui/styled-engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants