Future of runtime CSS-in-JS #2827
Replies: 5 comments 4 replies
-
Thank you for this thoughtful post 😃. I had not seen the discussion you linked, though our primary maintainer @Andarist clearly has.
We haven't discussed this topic, though @Andarist may already be thinking about it. I will make sure to discuss this with him if he doesn't comment here directly.
I think this would be such a major change to Emotion that it is not worth doing. My intuition says that it would be easier to write a new library than making Emotion work with static extraction.
Maybe — I will think about it.
Another maybe. If performance is super critical to your use case, I would not recommend runtime CSS-in-JS — it's convenient but that comes at a cost. I looked at Linaria and it does not seem to be very popular or active. I have heard of Vanilla Extract which is not terribly popular right now but seems to be gaining traction. For completeness, I will also mention CSS Modules / Sass Modules. It will also be interesting if Meta open sources stylex, their internal library which is mentioned in the react18-wg discussion.
Right at this moment, probably not — but if this turns out to be an actionable issue there may be opportunities to help. If you want to contribute to Emotion in general, feel free to DM me ( Edit: cc @mitchellhamilton |
Beta Was this translation helpful? Give feedback.
-
I think that this is very unlikely. CSS-in-JS might not be "recommended" by the React team but I doubt that it will become impossible.
I don't think we plan to introduce such things. There are two primary reasons for this:
Even though CSS-in-JS has its drawbacks it might be worth the tradeoff for many people. The lack of the required build step is a huge win for many projects.
We could make this clear in the docs - but to be honest I know plenty of fast sites using Emotion. It's not always about the tool itself but also how it's utilized by the apps/sites.
This should be judged on the case by case basis. It's not that Emotion became any slower since it got popular, in fact - it got faster in v11 since we've switched to the new version of the underlying parser (Stylis) and it has been improved in v4 (which I've also helped to get across the finish line). The question is - why it was OK to start using Emotion but it's not OK to continue using it any longer? 😉 I know the answer - it's hype. Perhaps we should be talking about actual perf numbers, tradeoffs, maintainability and other stuff - and not about the hype.
You always are welcome to help out :) That being said... there might be hope for people using Emotion who wants to stop relying on the runtime as much. There is this beautiful Compiled project that you can find here: https://compiledcssinjs.com/ I have not been checking it out lately so I'm not exactly sure what is its current status but I see that it's still active. If you care about this I would recommend you to reach out to their team and help out there. This is also part of the reason why I don't plan to do anything about the static extraction here - cause there are already projects doing this that aim to be a drop-in replacement for Emotion 😉 |
Beta Was this translation helpful? Give feedback.
-
Posted a docs PR to make this information more visible to our users as well as to encourage them to think critically about the runtime costs of Emotion. #2869 |
Beta Was this translation helpful? Give feedback.
-
Cross linking to my question here, #2857
|
Beta Was this translation helpful? Give feedback.
-
Any progress on this since that post article on Emtotion.js?
|
Beta Was this translation helpful? Give feedback.
-
Hi people!
I'd like to open up a discussion about the last section of the React 18 Library Upgrade Guide for CSS-in-JS libs.
Show the section, copy-pasted in here for convenience
First things first: I've caught up on the discussions about React 18 compatibility and it's great that Emotion.js has already adopted the new
useInsertionEffect
hook. Thank you! 🙌My remaining concerns are specifically about future versions of React:
So let's say that in React 20, something makes runtime CSS-in-JS impossible (or affects performance too much for this technique to make sense anymore). If I understand right, React wouldn't be providing a workaround.
So my questions:
Apologies if this has already been discussed elsewhere, and thanks in advance for your thoughts!
Beta Was this translation helpful? Give feedback.
All reactions