mui / material-ui

Material UI: Ready-to-use foundational React components, free forever. It includes Material UI, which implements Google's Material Design.
https://mui.com/material-ui/
MIT License
92.38k stars 31.81k forks source link

[material-ui] Questions regarding Pigment CSS usage #42437

Open kealjones-wk opened 1 month ago

kealjones-wk commented 1 month ago

Related page

https://mui.com/blog/introducing-pigment-css

Kind of issue

Missing information

Issue description

Sorry if this is not the best place to discuss this, I was not sure where to, if you have a better place please point me to that! :)

My team has a very specific way of using material-ui, we expose our components for usage in TypeScript and Dart. Pigment seems to depend on source transformations which would be fine for our TypeScript consumers but would possibly be a hard stopper for our Dart consumers, unless we are able to provide similar functionality with a custom dart build step.

So questions:

  1. Will Pigment be the only way to use mui-material going forward? or will it be an optional dependency? Meaning could we continue to use emotion as our sx & styled engine even after Pigment?
  2. Are there plans to drop support for Emotion at some point? If not, will there be disadvantages to staying on Emotion?
  3. Will sx continue to work on material-ui components under Emotion, even without Pigment's source transformations?
  4. Is there possibly alternate ways to use Pigment that doesn't require source transformations?

Context

No response

Search keywords: pigment, css-in-js, emotion, css

danilo-leal commented 1 month ago

Heya @kealjones-wk, thanks for the issue! I can shed some light on some of these questions:

  1. No! For Material UI v6, Pigment CSS will be opt-in. Emotion will continue to be there for folks who don't want to use it.
  2. No plans at the moment. As far as I can tell, the biggest disadvantage is not getting the performance improvements + React Server Components compatibility that comes with Pigment (due to the zero-runtime nature).
  3. Yeah, the DX should be pretty much the same. The sx prop should remain there.
  4. Tagging @brijeshb42 so he can help out with this one in particular and also double-check everything else 😄
brijeshb42 commented 1 month ago

Adding to @danilo-leal's answer, for point 4, not at the moment. Pigment CSS needs source transformations to extract out the css and make the bundle size smaller. We do have a plan in future to make Pigment act as runtime CSS-in-JS as default (internally, it might continue to use Emotion) and if you configure your bundler, it'll do the CSS extraction. So there shouldn't be any worries on your side.

kealjones-wk commented 1 month ago

Not that this is actually anything we plan to do, but for point 4 I was mainly curious if Pigment's css function actually has to be removed or if it would actually return the correct className if it was executed at runtime?

brijeshb42 commented 5 days ago

Currently, there is a tiny runtime, but only for the styled call. Rest all the exports only exist at build-time and are replaced with a string at runtime. So they won't be callable if not transformed.