Skip to content

[system] Support new style engine that generates static CSS files at build time #34826

@oalexdoda

Description

@oalexdoda

(issue heavily edited by @oliviertassinari)

Summary 💡

I recently found an article that breaks down in detail why CSS-in-JS doesn't have the best performance https://dev.to/srmagura/why-were-breaking-up-wiht-css-in-js-4g9b. One of the core features I'm using with MUI is the sx / Emotion / CSS-in-JS feature.

This is a proposal to provide a new style engine inspired by the zero-runtime CSS-in-JS libraries: extract all the CSS-in-JS, split it into CSS modules when building the app for production, and serve the styles that way instead. The goal is to retain as much as possible of the current API while having no runtime.

There should be as few breaking changes as possible, and provide a progressive migration story. We wouldn't deprecate the other style engines.

Examples 🌈

Motivation 🔦

The current CSS-in-JS runtimes:

  1. takes more CPU cycles to add the styles than raw CSS would take.
  2. increases bundle size
  3. are not compatible with react server component Plans to support Next.js 13 - /app directory emotion-js/emotion#2928 Nextjs 13 styled-components/styled-components#3856 and might never be Improve Next.js support #34905 (comment) Add React Server Component support for Layout components (Grid, Stack, Container) #35993
  4. don't work well with Next.js v13

We have seen developers use Tailwind CSS because they are afraid that Material UI is not fast enough. But by moving, they get, what we could argue is a poorer DX with the utility CSS class name. The problems a. you unlearn CSS with utility classes, b. the utility classes are harder to use for conditional styling.

Also, this example shows that it's all about the perception of performance and not the actual performance. Having no runtime would make it very clear that the performance should "logically" be equivalent.

What success looks like?

Two ways to quantify success in this effort:

Benchmarks

Metadata

Metadata

Assignees

Labels

package: pigment-cssSpecific to Pigment CSS.package: styled-engineSpecific to @mui/styled-engineperformancescope: systemThe system, the design tokens / styling foundations used across components. eg. @mui/system with MUItype: enhancementIt’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions