CSS-in-JS Performance Concerns - (sx)
See original GitHub issueDuplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Summary š”
I recently found an article that breaks down in detail why CSS-in-JS is bad for performance. One of the core features Iām using with MUI is the sx / emotion / css-in-js feature and Iām wondering what the MUI dev community thinks about this and whether thereās any potential solutions to tackle the performance concerns.
https://dev.to/srmagura/why-were-breaking-up-wiht-css-in-js-4g9b
Are there any plugins or libraries that can basically extract all the CSS-in-JS, split it into CSS modules when building the app for production, and serve the styles that way instead?
Examples š
No response
Motivation š¦
To help overcome these issues with MUIās CSS-in-JS:
- Frequently inserting CSS rules forces the browser to do a lot of extra work
- CSS-in-JS adds runtime overhead
- CSS-in-JS increases your bundle size
Issue Analytics
- State:
- Created a year ago
- Reactions:5
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Performance - JSS
JSS has some performance advantages. Incremental compilation and rendering (as soon as needed). Rendered styles are cached. Compilation and DOM Rules creationĀ ...
Read more >Which is better CSS-in-JS or CSS for large and scalabe project?
The article that I read said CSS-in-CSS(css, scss, css-module) has better performance than CSS-in-JS(styled-components, emotion...).
Read more >CSS Modules vs CSS-in-JS. Who wins? - DEV Community ā ā
Developers have started to think of solving this problem. ... server - that is still a performance penalty and will slow down the...
Read more >How to increase CSS-in-JS performance by 175x - ITNEXT
That it can introduce new problems such as breaking because Storybook uses another version of emotion, theme Providers breaking when importedĀ ...
Read more >Is there a performance difference between the sx prop and the ...
You can find information about the performance difference for static styles between JSS and Emotion in the following issues:.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

It would be awesome if it was possible to move to a static extraction option. The biggest challenges would likely be:
Other ideas:
The end goal is to get points c. and d. as close as possible to a.
https://mui.com/system/getting-started/usage/#performance-tradeoffs.
To be fair, d. seems good enough in most cases. Itās usually not good enough when you have a large DOM, at which points, you need to rewrite a bit how the styles are applies, which costs you time. If you open https://pagespeed.web.dev/report?url=https%3A%2F%2Fmui.com%2F&form_factor=mobile, itās not āinsanely greatā as would say Steve. I doubt that the bottleneck is styling, (e.g. https://nextjs.org/ uses CSS modules and performs worse than https://mui.com/) but more the amount of hydration that happens. Server-side React component could help a lot, for which, we need MUI System to be compatible with.
Some ideas:
Any way to get something like this in MUI natively?