Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.8k
Pigment CSS: RFC discussion#40844
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Continuing the discussion from the RFC issue started in#38137 |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 6🚀 19
Replies: 18 comments 56 replies
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Are there plans to make this zero runtime solution agnostic from MUI? Would be great to be able to build on this solution in other component libs as well |
BetaWas this translation helpful?Give feedback.
All reactions
👍 5
-
Yes, this is the plan and how it is current designed. |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 2
-
There was also discussion on making it agnostic to React. |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 3
-
I hope so too |
BetaWas this translation helpful?Give feedback.
All reactions
-
I would love for some solution that works well with CSS modules which is available in both Next.js and Astro, (I think this probably means css vars?) The current theme and runtime styling solution really makes MUI in Astro sort of a non-starter too, so just tossing it out there to keep that framework in mind. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 2
-
This is a great point. We can look into creating an example project and show how it can work. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Super |
BetaWas this translation helpful?Give feedback.
All reactions
-
Could you, please, clarify if MUI team already decided to use |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Yes. We are already moving ahead with zero-runtime. No |
BetaWas this translation helpful?Give feedback.
All reactions
👍 4
-
Thank you for the clarification! We should avoid getting back to pros and cons to keep this focused on the actual scope. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 3
-
Thank you, I understand too |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
FWIW, StyleX isn't "zero runtime". Having no runtime at all is not practical for atomic CSS libraries, as a runtime is needed to perform merging of styles during composition to avoid the kind of style conflicts that are common when using libraries like Tailwind. The runtime we use for StyleX is calledstyleQ - it's small, fast, and flexible enough to be used with any compiler not just StyleX. Although the repo has independent benchmarks, we also tested it on facebook.com where the runtime is called 15K times on the feed screen - it took 15ms and was 5x faster than the runtime we were using before. It's very easy to introduce slow paths in a runtime if you're not benchmarking after every change. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 7
-
Thanks for the explanation! Interestingly, even with 15K calls on the runtime page, it only works 15ms. Have you noticed any features when scaling to larger components or when using style compositions more complex? |
BetaWas this translation helpful?Give feedback.
All reactions
-
Excited for zero runtime! How can I write MUI system style code today that will be compatible with the new zero runtime? Will both of the below flavors be supported? <Buttonsx={{mb:3}}>// or<Boxmb={3}> |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I think the dream would be:
|
BetaWas this translation helpful?Give feedback.
All reactions
👍 3❤️ 2
-
Yes, the idea with sx on any component really makes Box less needed. I wonder how you see the transition from Box to this approach for large code bases – will there be any migration tools when emotions stop being runtime? |
BetaWas this translation helpful?Give feedback.
All reactions
-
Excited for this as emotion js still doesn't support streaming server side rendering :/emotion-js/emotion#2800 |
BetaWas this translation helpful?Give feedback.
All reactions
-
Yes, it's really expected! 😅 I hope that with this change streaming SSR will become real without big crutches. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Hi Team, Are there any plans to support an easy migration from v4 makeStyles API? It seems to have fairly decent usage still ![]() |
BetaWas this translation helpful?Give feedback.
All reactions
🚀 1
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Looks like what we basically need is a method that takes in a nested object and returns an object of classnames: MUI v4: constuseStyles=makeStyles((theme)=>({title:{color:theme.palette.primary.main,}}));functionApp(){constclasses=useStyles();return<divclassName={classes.title}>Iaminvisible</div>;} Pigment css API: consttitle=css(({ theme})=>({color:theme.colors.primary,fontSize:theme.spacing.unit*4,fontFamily:theme.typography.fontFamily,}));functionApp(){return<divclassName={title}>Iaminvisible</div>;} Proposed new "makestyles" conststyles=makeStyles(({theme})=>({title:{color:theme.colors.primary}}))functionApp(){return<divclassName={styles.title}>Iaminvisible</div>;} There could be some minor differences like if response can be used directly without hook as in v4, but still it should be mostly easy to migrate@brijeshb42 what do you think? |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Thee is no plan to support the makeStyles API today. Until we can demonstrate that Pigment CSS works, this looks like a distraction. JSS continues to work. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Of course, thanks for the explanation. It is logical to first prove that Pigment CSS works stably before considering makeStyles. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Hey@brijeshb42, I tried out the recently released@pigment-css/react in my Next.js app and got the error: I'm wondering if it has to do with me using turbopack. Will the Next.js plugin support turbopack? Note, I'm wrapping my |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Let's move this to a separate issue. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Pigment works by injecting a Webpack plugin into the next config. So as of right now, we won't be able to support turbo till it's atleast not experimental or it exposes a way to have plugins. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
We might want to create an issue for this, it looks equivalent tofacebook/stylex#63. |
BetaWas this translation helpful?Give feedback.
All reactions
-
@brijeshb42, issue created:https://github.com/mui/material-ui/issues/41449 |
BetaWas this translation helpful?Give feedback.
All reactions
-
Understood, thanks for the explanation! Then it is logical that Turbo support is postponed until there is a stable way to add plugins. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
How to start adapting |
BetaWas this translation helpful?Give feedback.
All reactions
-
I think, mui v6 is on the way for that |
BetaWas this translation helpful?Give feedback.
All reactions
-
There is no official guide for migrating MUI 5 to Pigment zero runtime yet, but it is logical to start with the components that are least dependent on JSS or makeStyles. Then gradually replace the styles with Pigment CSS via sx or styled API. |
BetaWas this translation helpful?Give feedback.
All reactions
-
After all the discussion from the issue mentioned in OP. I see no mention of atomic styles in the readme. Is this intended for a future release or something that has been dismissed? Thanks! |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Please understand that I'm coming from this as a layman. I don't understand the inner workings of these new css libraries. The value proposition would be that the inital css is overwritten by a prop. A quick example would be something like: import{css,prop}from"@pigment-css/react";import{CSSProperties}from"react";constbaseStyles=css({color:"red",background:"white",fontWeight:"normal",});interfacecustomComponentProps{propStyle:CSSProperties}functionCustomComponent({ propStyle}:customComponentProps){return(<div{...prop(baseStyles,propStyle)}> some text</div>)} The result is that the CustomComponent can have certain styles added and overriden. exportfunctionPage(){conststyle={color:"green",fontWeight:"bold","&:hover":{color:"blue"}}return(<CustomComponentpropStyle={style}/>)} Unfortunately, this does not translate to my POC. It's vastly more complicated. An example of my poc. I'm instantiating the components via the styled api: badge.css.ts Badge.tsx (as a package)t: The problem I have using the Btw, this was a test to see what was possible. As I'm still new to the library. My actual use case is something like:
As the component would be used in this manner: Hopefully this makes more sense now? Oh to clarify as well. All the values passed are static. None of them are dependent on props themselves. So this is all focused on buildtime. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I'd say this is more suited when atomic css is involved, since here, you'd want to follow |
BetaWas this translation helpful?Give feedback.
All reactions
👍 2
-
@brijeshb42 Alright, good to know! Many thanks! |
BetaWas this translation helpful?Give feedback.
All reactions
-
@paulm17 Pigment CSS relies on CSS Modules, CSS Modules can be code-split by the bundler based on what's visible on the screen. These CSS files can also be removed from the DOM when moving to a different page. Atomic CSS shines when you have large CSS files and you don't code-split. ![]() withhttps://vercel.com homepage, it's written with CSS Modules: ![]() The difference isn't that significant with Next.js. For example withhttps://vitejs.dev/guide/features.html#css-code-splitting it might work even better. Now, we could consider an atomic CSS mode in the future, like even with CSS Modules code split, it could bring another level of performance in addition to code splitting. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 2
-
Good question! From what I understand, atomic styles might be planned for a future release, but nothing official has been mentioned yet. |
BetaWas this translation helpful?Give feedback.
All reactions
-
I have a question about how to leverage Pigment-CSS with runtime theme support. I see in the Pigment docs there ways to handle runtime based css for a component and separately about support things in the webpack/nextjs configs but I need a merge of the 2. We have a SaaS based product that builds a custom theme at runtime based on the tenant's settings and then use the theme through the app. This is all don't in the app.jsx Is there a way to do that with pigment as well are are we going yo start needing to used styled() everywhere now |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I dont think im explaining it very well. So in our app.jsx we make a call like this, in which we create a theme object with various values from Runtime that are passed down to the app.jsx via props. Rough example below We then pass this runtime theme to the Then when we use any MUI component it will naturally pull in the Runtime Primary/Secondary colors automatically. If we have some components that wrap MUI components or that use
|
BetaWas this translation helpful?Give feedback.
All reactions
👀 1
-
@brijeshb42 any update to my last comment? |
BetaWas this translation helpful?Give feedback.
All reactions
-
You can easily do so using a constcss=` --palette-primary-main:${backend.value.primary.main} /* similarly set other variable values */`; // on CSR appsconststyle=document.createElement('style')document.head.appendChild(style) // on SSR apps<style>{css}</style> We'll also be providing an export from |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Awesome that's for the info and examples. Also just a shout out to all the hard work you guys have done getting pigment off the ground. Can't wait to start using it more in our MUI based areas/apps |
BetaWas this translation helpful?Give feedback.
All reactions
🎉 2
-
Totally agree! Huge kudos to the team for getting Pigment off the ground. Excited to see it in action in MUI apps! |
BetaWas this translation helpful?Give feedback.
All reactions
-
Please don't forget about the |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Absolutely! The css prop is super powerful—it gives the utility of Tailwind while letting us write more natural CSS. Definitely don’t want it forgotten. |
BetaWas this translation helpful?Give feedback.
All reactions
-
How does this affect/relate to Joy, especially regarding the efforts to rely on CSS-variables where possible? |
BetaWas this translation helpful?Give feedback.
All reactions
-
Heya@kxseilerjo. I'm not sure we can say the details yet, as we're primarily focused on converting Material UI components for now. Generally speaking, we'll return the focus to Joy UI together with the Material UI v7 cycle. We'll iron out the Material UI <> Joy UI and Joy UI <> Pigment CSS relationship then. |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 1
-
Great question! I’m also curious how this ties into Joy, especially with the push to rely on CSS variables. Will Pigment fully integrate with that approach or are there trade-offs? |
BetaWas this translation helpful?Give feedback.
All reactions
-
I have an app that is built from dynamic settings. So the setttings are fetched and then merged into the build at run time. So, I can inject any available sx properties this way. It allows me to customize a version of the app per tenant. Will I be able to do this with pigment? |
BetaWas this translation helpful?Give feedback.
All reactions
-
I read that eventually you are moving completely to pigment, which I can understand why for apps that are completely built at run time. So, does that mean that this use case will be completely unsupported by MUI in the future? |
BetaWas this translation helpful?Give feedback.
All reactions
-
You could probably set the dynamic settings as css vars instead and have it set values in runtime - that should work |
BetaWas this translation helpful?Give feedback.
All reactions
-
I am not sure I understand this 100%. From the examples I have seen, I would have to define all possible css vars to be able to use the same system as I am using now. Because I don't know which css vars will be needed at build time for a Box component, for example. There could be none, 1, 2, etc. for each instance of the Box component. Meaning they could all be different. Maybe I am misunderstanding how it would be implemented. |
BetaWas this translation helpful?Give feedback.
All reactions
-
I just wanted to add the explanation for why I am doing things this way, in case it helps to understand it. The main reason I am doing this is that it allows me to change a client's app without needing to do a redeployment of the code base, which might introduce bugs for other tenants. And because no deployment is needed, I can make changes and iterate very quickly which gives a much better outcome for the client. It makes for very slightly slower app performance, but it is much faster in terms of making changes. |
BetaWas this translation helpful?Give feedback.
All reactions
-
So for a box lets say you change padding, margin, boxShadow, borderRadius for eg. define all these with standard values at build time. and change it in runtime. It's a chore to define all possible properties for sure, but if you can limit it might be manageable. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
As I can see PigmentCSS focused on MPA(multi-page app, NextJs, and so on). Does SPA (single-page app) with PigmentCSS still work similarly to Emotion? Will it include some sort of plugin for Webpack/Esbuild? Because there is nothing about this in the docshttps://mui.com/material-ui/migration/migrating-to-pigment-css/ |
BetaWas this translation helpful?Give feedback.
All reactions
-
I have a use case similar to@experimarketing . We have a base theme that's applied on page load, but immediately after a request is made which fetches a custom them our users can configure. It alters things like the Unlike experimarketing's example however, all of this happens by merging the base and user themes and feeding the result to the |
BetaWas this translation helpful?Give feedback.
All reactions
-
@GMchris,@experimarketing Hi there! Depending on the adjustments you need to the base theme, I would override the styles using the CSS variables the theme exposes. By doing so, you can override the styles at any point. You can even unmount that customization and get back to standard (the built theme). |
BetaWas this translation helpful?Give feedback.
All reactions
-
@acomanescu After doing some research on this and thinking more about it, I don't think that using CSS vars allows me to do what I need. There are hundreds of css variables per component. Generally, I will only use a few, but occasionally you need to really customize a component. And I need to be able to do that when needed. So, I don't think this works for my use case. Does anyone know what the roadmap is for CSS for MUI? |
BetaWas this translation helpful?Give feedback.


