question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RFC: Static CSS Extraction

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:69
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
brennjcommented, 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.

2reactions
b-botcommented, Jul 6, 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)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Don't I Sell the Idea of Static Extraction with CSS-in-JS?
I create a CSS Rule(s) using the hash as the class name. I put those Rule(s) into a stylesheet that exists somewhere in...
Read more >
What's New in Next.js 13 - AppSignal Blog
Layouts in Next.js make it easier to extract shared code between multiple pages. layout.tsx accepts another layout or a page as a child....
Read more >
RFC 9204: QPACK: Field Compression for HTTP/3
This specification defines QPACK: a compression format for efficiently representing HTTP fields that is to be used in HTTP/3. This is a variation...
Read more >
Website Performance in 2021: React Server Components ...
In this post I highlight a few current and upcoming features we can utilize to boost website performance in our React websites.
Read more >
PHP date_format() Function - W3Schools
... CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more. ... r - The RFC 2822 formatted date (e.g. Fri, 12 Apr...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found