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

[system] Support variants in theme.styleOverrides #40690

Merged
merged 16 commits into from
Feb 6, 2024

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Jan 19, 2024

Motivation

Result

Reduced ~120 lines of duplicate code by moving inside one processStyleArg function which makes theme.styleOverrides.*.variants work.

Next step

Consider deprecating the theme.variants API in #30412 and add TODO to remove it in the next major version.


@siriwatknp siriwatknp added package: system Specific to @mui/system enhancement This is not a bug, nor a new feature labels Jan 19, 2024
@mui-bot
Copy link

mui-bot commented Jan 19, 2024

Netlify deploy preview

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

@material-ui/core: parsed: -0.17% 😍, gzip: -0.19% 😍
@material-ui/lab: parsed: -0.36% 😍, gzip: -0.40% 😍
@material-ui/system: parsed: -1.25% 😍, gzip: -1.20% 😍
@mui/material-next: parsed: -0.28% 😍, gzip: -0.28% 😍
@mui/joy: parsed: -0.20% 😍, gzip: -0.26% 😍

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 9fdd007

@siriwatknp siriwatknp marked this pull request as ready for review January 22, 2024 11:45

if (componentName && overridesResolver) {
expressionsWithDefaultTheme.push((props) => {
const theme = resolveTheme({ ...props, defaultTheme, themeId });
const styleOverrides = getStyleOverrides(componentName, theme);
Copy link
Member Author

Choose a reason for hiding this comment

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

getStyleOverrides is not reused, so remove it to not shift between functions.

styledArgVariants,
);
variantStyles.forEach((variantStyle) => {
result = deepmerge(result, variantStyle);
Copy link
Member Author

Choose a reason for hiding this comment

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

I just noticed this deepmerge. I think we should remove it and let emotion/styled-components handle it. Both of them already support array of styles.

@mnajdova Should we try to remove it? the perf should be a bit better while producing the same result.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, would it work if we remove it? From what I remember some of these definitions are merged into one style arg, this is what I remember.

Copy link
Member Author

@siriwatknp siriwatknp Feb 1, 2024

Choose a reason for hiding this comment

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

Yes, it would work but there is a tiny difference in the dev tool

without merging style, you will see all the styles declared in the variants when props are matched:

.hashed-variant2:hover {
  color: red;
}

.hashed-variant1:hover {
  color: green;
}

but the results (cascading) are the same.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd not merge so that the logic does not depend on the deepmerge but rely on the style engine.

Copy link
Member

Choose a reason for hiding this comment

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

Have we tried removing the deepmerge and see if some test are failing?

Copy link
Member Author

Choose a reason for hiding this comment

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

@mnajdova All green, see the change in this 473e62d

@siriwatknp siriwatknp merged commit e57e674 into mui:master Feb 6, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is not a bug, nor a new feature package: system Specific to @mui/system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants