Skip to content

[system] Shorten class names in production#27932

Merged
oliviertassinari merged 1 commit intomui:nextfrom
oliviertassinari:system-short-classnames-production
Sep 2, 2021
Merged

[system] Shorten class names in production#27932
oliviertassinari merged 1 commit intomui:nextfrom
oliviertassinari:system-short-classnames-production

Conversation

@oliviertassinari
Copy link
Copy Markdown
Member

@oliviertassinari oliviertassinari commented Aug 23, 2021

Testing this idea #27838 (comment) out.

It doesn't make a major difference but it seems harmless and consistent with how emotion & styled-components handles debuggable class names.

I have tried https://www.webpagetest.org/ but the variance was too high to see a real difference. So I guess, it's more around, do we want the long class names in production at the expense of an inlined CSS a bit larger?

@oliviertassinari oliviertassinari added performance scope: system The system, the design tokens / styling foundations used across components. eg. @mui/system with MUI labels Aug 23, 2021
@oliviertassinari oliviertassinari marked this pull request as draft August 23, 2021 18:38
@mui-pr-bot
Copy link
Copy Markdown

mui-pr-bot commented Aug 23, 2021

Details of bundle changes (experimental)

Generated by 🚫 dangerJS against 76fe285

@oliviertassinari
Copy link
Copy Markdown
Member Author

@mnajdova what do you think about this one?

Copy link
Copy Markdown
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

Makes sense, sorry I must have missed the PR, thanks for mentioning me

@oliviertassinari oliviertassinari merged commit 4772a69 into mui:next Sep 2, 2021
@oliviertassinari oliviertassinari deleted the system-short-classnames-production branch September 2, 2021 18:09
@oliviertassinari
Copy link
Copy Markdown
Member Author

oliviertassinari commented Sep 2, 2021

I have tested with styled-components, it works too. I'm moving forward on the simple basis that it's closer to how emotion and styled-components behave. It might help developers to feel more "at home", e.g. they could wonder if they correctly set NODE_ENV = 'production' if they keep seeing the dev class names in production.

@maxtechera
Copy link
Copy Markdown

maxtechera commented Sep 23, 2021

@oliviertassinari @mnajdova - Hey! Thanks a lot for the library! I see how this improves the length of the inlined styles.
Although it changes how custom components built with styled() work compared to native MUI components which include at least the global class names.

In particular, this change broke customization of custom components using selectors like [class$=Component-slot] to target as you would with [class$=MuiLink-root].
This still works on development but no longer in production, and AFAIK is the only solution to targeting when using nested themes.

This was working previously in production as this check was not in place, but no longer does.

Is this no longer supported? and/or is there a new way to do this or workaround? Would you be interested in supporting this feature parity for MUI components and custom components? Maybe through enabling the global class names.

@oliviertassinari
Copy link
Copy Markdown
Member Author

oliviertassinari commented Sep 23, 2021

@maxtechera do you have a reproduction of the behavior so we have context? There are too many unknown for me to really understand the problem you are trying to solve.

If I had to guess, it seems that you are creating custom components with the styled() method, and using the component name, slot name options. Did you consider adding the class names on the element directly?

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

Labels

performance scope: system The system, the design tokens / styling foundations used across components. eg. @mui/system with MUI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants