Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip][system] Try reordering the presedence of variants over base styles #42276

Draft
wants to merge 2 commits into
base: next
Choose a base branch
from

Conversation

mnajdova
Copy link
Member

@mnajdova mnajdova commented May 17, 2024

We discussed internally how the precedence of overrides should work with the new variants API (the discussion started around the Pigment CSS product, see more info here).

From the initial investigation, it is possible for us to dictate how the order of the base styles/variants are handled along one instance of component, styled(), styleOverrides, variants, however, I didn't find a way how to augment the order of how they are added across components, for example using styled(Button). Check the tests for more details (I skipped the one that is not working).

Considering it is not possible to do it consistently between theme vs styled() overrides, I would lean toward not implementing any change and document this as a different behavior between Pigment CSS and MUI System and add instructions around best practices of how the overrides should be written so that people know how to not get into this kind of differences in behavior.

@mnajdova mnajdova added the package: system Specific to @mui/system label May 17, 2024
@mnajdova mnajdova changed the title [wip] Try reordering the presedence of variants over base styles [wip][system] Try reordering the presedence of variants over base styles May 17, 2024
@mui-bot
Copy link

mui-bot commented May 17, 2024

Netlify deploy preview

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

packages/material-ui/material-ui.production.min.js: parsed: +0.17% , gzip: +0.09%
@material-ui/lab: parsed: +0.31% , gzip: +0.18%
@material-ui/system: parsed: +1.09% , gzip: +0.48%
@mui/joy/Container: parsed: +1.36% , gzip: +0.62%
TextField: parsed: +0.60% , gzip: +0.29%
SpeedDialAction: parsed: +0.72% , gzip: +0.31%
ToggleButtonGroup: parsed: +1.51% , gzip: +0.59%
@mui/joy: parsed: +0.18% , gzip: +0.10%
@mui/joy/AccordionGroup: parsed: +1.23% , gzip: +0.52%
ListItemButton: parsed: +1.17% , gzip: +0.46%
Masonry: parsed: +1.52% , gzip: +0.57%
@material-ui/core: parsed: +0.15% , gzip: +0.08%
Alert: parsed: +1.02% , gzip: +0.40%
ListItemText: parsed: +1.51% , gzip: +0.56%
CardHeader: parsed: +1.50% , gzip: +0.56%
PaginationItem: parsed: +1.04% , gzip: +0.41%
@mui/joy/Switch: parsed: +1.18% , gzip: +0.48%
IconButton: parsed: +1.19% , gzip: +0.45%
Unstable_Grid2: parsed: +1.46% , gzip: +0.54%
Chip: parsed: +1.05% , gzip: +0.41%
and 178 more changes

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against c562855

],
});

const B = styled(A)({
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the use-case that still doesn't work - using the styled() util.

root: {
paddingTop: '20px',
// this should not override the one from A
backgroundColor: 'rgb(255, 255, 255)',
Copy link
Member Author

Choose a reason for hiding this comment

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

Controlling the order of the styleOverrides is possible, as we are the one that handles when these are added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: system Specific to @mui/system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants