Skip to content

[system] Keep the unit of container query sizes - #49669

Merged
ZeeshanTamboli merged 3 commits into
mui:masterfrom
b84330808:fix-container-query-size-units
Nov 12, 2026
Merged

ZeeshanTamboli merged 3 commits into
mui:masterfrom
b84330808:fix-container-query-size-units

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

The container query shorthand drops rules whose size has a unit. With a theme from createTheme():

sx={{ padding: { '@': 0, '@20em': 2, '@40em': 4 } }}
// '@container (min-width:20empx)': { padding: '16px' },
// '@container (min-width:40empx)': { padding: '32px' },

sx={{ padding: { '@40rem/sidebar': 4 } }}
// '@container sidebar (min-width:40rempx)': { padding: '32px' }

Browsers ignore 40empx, so these styles never apply. The container queries page uses @40em and @20em in its "sorted correctly" example, and the error for an invalid shorthand suggests @40rem/sidebar.

The shorthand calls theme.containerQueries(name).up(size), and breakpoints.up() appends the theme unit to any value that is not a breakpoint key. Without a containerQueries on the theme, the fallback in breakpoints.ts already leaves such a size alone and gives @container (min-width:40em).

This changes up() to use a string that has its own unit as is. Numbers, numeric strings and breakpoint keys still get the theme unit, so @600 and @sm don't change. down() and between() are unchanged: they subtract the step from the value, which needs a number or a key.

I also updated the caveat on the docs page that says @500px won't render correctly. With this change it gives the same query as @500.

Added tests in createBreakpoints.test.js and cssContainerQueries.test.ts. Both fail on master.

I used Claude Code to write this change.

`breakpoints.up()` appended the theme unit to every value that is not a
breakpoint key, so a size that already had a unit got a second one. The
container query shorthand goes through it, so `@40em` and
`@40rem/sidebar` in `sx` produced `min-width:40empx` and
`min-width:40rempx`, which browsers ignore.

A string with its own unit is now used as is. Numbers, numeric strings
and breakpoint keys still get the theme unit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@code-infra-dashboard

code-infra-dashboard Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Deploy preview

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+79B(+0.01%) 🔺+20B(+0.01%)
@mui/lab 🔺+79B(+0.25%) 🔺+23B(+0.29%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 🔺+79B(+0.11%) 🔺+17B(+0.07%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Performance

No regressions in 32 benchmarks · ran 2m 06s · details


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

@zannager zannager added the scope: system The system, the design tokens / styling foundations used across components. eg. @mui/system with MUI label Nov 10, 2026
@ZeeshanTamboli ZeeshanTamboli added type: bug It doesn't behave as expected. needs cherry-pick The PR should be cherry-picked to master after merge. v9.x labels Nov 12, 2026

@ZeeshanTamboli ZeeshanTamboli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks. There's one separate issue this PR doesn't touch: the TypeScript type up: (key: Breakpoint | number) doesn't accept '500px'. So the documented up('500px') example still fails type-checking. Widening that type would change the API, so it belongs in a follow-up if anyone wants it.

@ZeeshanTamboli
ZeeshanTamboli enabled auto-merge (squash) November 12, 2026 12:21
@ZeeshanTamboli
ZeeshanTamboli merged commit 4c499c5 into mui:master Nov 12, 2026
26 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Cherry-pick PRs will be created targeting branches: v9.x

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

Labels

needs cherry-pick The PR should be cherry-picked to master after merge. scope: system The system, the design tokens / styling foundations used across components. eg. @mui/system with MUI type: bug It doesn't behave as expected. v9.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants