Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Static CSS Extraction #859

Closed
segunadebayo opened this issue Jun 14, 2020 · 5 comments
Closed

RFC: Static CSS Extraction #859

segunadebayo opened this issue Jun 14, 2020 · 5 comments
Labels
help wanted 🆘 Extra attention is needed Type: Feature 🚀 Issue or PR that adds a feature or improvement

Comments

@segunadebayo
Copy link
Member

Background:

Given the current API of Chakra UI, we're looking to transition Chakra to my ideal vision after the stable TypeScript release.

One of the downsides of CSS-in-JS, particularly the styled-system approach is the runtime performance issues. Here's what I mean:

  • You pass some style props to any component
  • Chakra UI uses styled-system functions to transform the style props you pass to CSS objects
  • Chakra UI uses emotion to convert the CSS object to a class name (using some hashing strategy) and appends a style tag to the head of the browser

This process happens very often during the lifetime of any Chakra component, and performance issues might become noticeable with very fast, frequent updates.

Ideas on how to solve this

  • Static CSS Extraction: Figure out how to generate static CSS files based on the style props at build time, so there's almost zero runtime cost.

  • Prefer CSS variables to Context: Because CSS variables work like React context, we can simply switch the current implementation to write theme specs to:root via css variables. Then update styled-system functions.

Ideally, we'd love to leverage existing innovations like Linaria and Otion so we're going to explore those first.

Ending remarks

Figuring out Static CSS extraction will be the next innovation in CSS-in-JS and will help improve adoption at scale.

I'd love to hear what you think, and if you're inclined to solve this problem, please comment below let's collaborate.

Cheers.

@segunadebayo segunadebayo added Type: Feature 🚀 Issue or PR that adds a feature or improvement help wanted 🆘 Extra attention is needed labels Jun 14, 2020
@segunadebayo segunadebayo pinned this issue Jun 14, 2020
@segunadebayo
Copy link
Member Author

After some research, Compiled CSS-in-JS by the Atlassian team seems to be an amazing solution.
https://compiledcssinjs.com/docs/

@segunadebayo segunadebayo changed the title Static CSS Extraction RFC: Static CSS Extraction Jun 14, 2020
@brennj
Copy link

brennj commented Jun 14, 2020

Would love this @segunadebayo, think this could be really really beneficial. I haven't played with it in depth, but there could be something interesting looking into https://github.com/seek-oss/treat, they seem have a good solution in how they use it for their Braid design system.

@b-bot
Copy link

b-bot commented Jul 4, 2020

I've been thinking about what the ideal design system stack would look like.
I came across this article by the FB engineering team and it looks like they settled on CSS variables.
https://engineering.fb.com/web/facebook-redesign/

The dark mode requirements are an obvious one but they seem to elude that this is going to be the preferred way going forward and considering their investment in React it may be a good idea to look into the reasons for their choices in relation to your vision for Chakra UI.

@segunadebayo Maybe a dumb question but what was the motivation in not using CSS variables from the start as it seems the project this is based on does so by default? (And why it is completely SSR compatible)

@segunadebayo segunadebayo unpinned this issue Aug 3, 2020
@segunadebayo
Copy link
Member Author

Thanks for all the comments so far.

We'll look into this sometime in the future.

@samuelcastro
Copy link

samuelcastro commented May 11, 2021

Hi @segunadebayo, any updates on this topic? I'm considering chakra-ui for a new project but I'm wondering whether or not it's compatible with Linaria. I don't want to use Emotion due to performance implications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted 🆘 Extra attention is needed Type: Feature 🚀 Issue or PR that adds a feature or improvement
Projects
None yet
Development

No branches or pull requests

4 participants