question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS-in-JS Performance Concerns - (sx)

See original GitHub issue

Duplicates

  • 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:

  1. Frequently inserting CSS rules forces the browser to do a lot of extra work
  2. CSS-in-JS adds runtime overhead
  3. CSS-in-JS increases your bundle size

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:5
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
oliviertassinaricommented, Oct 31, 2022

It would be awesome if it was possible to move to a static extraction option. The biggest challenges would likely be:

  1. How to deliver the same great DX?
  2. How to make the amount of breaking changes acceptable?

Other ideas:

The end goal is to get points c. and d. as close as possible to a.

Screenshot 2022-10-30 at 23 26 28

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.

Screenshot 2022-10-30 at 23 44 45
3reactions
altechzillacommented, Oct 19, 2022

Some ideas:

Any way to get something like this in MUI natively?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found