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] Shorten class names in production #27932

Conversation

oliviertassinari
Copy link
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 marked this pull request as draft August 23, 2021 18:38
@mui-pr-bot
Copy link

mui-pr-bot commented Aug 23, 2021

Details of bundle changes (experimental)

Generated by 🚫 dangerJS against 76fe285

@oliviertassinari
Copy link
Member Author

@mnajdova what do you think about this one?

Copy link
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
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

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
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
package: system Specific to @mui/system performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants