Color modes not using CSS custom properties
See original GitHub issueLooking at the code I see that to set the color mode, it relies on the emotion theme provider:
This generates unnecessary class names in order to change the color even though all the custom props are in DOM:
I’ve build a quick experiment where I’m relying on changing only the className of the body
element and it works as expected without any additional re-rendering caused by emotion.
I’m wondering if the current behavior is intentional and what’s the motivation to rely on have JS runtime for changing color mode?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:32 (10 by maintainers)
Top Results From Across the Web
Using CSS custom properties (variables) - MDN Web Docs
This example is just like the last one, except we use a custom property. As expected, the browser substitutes the value of --text-color...
Read more >CSS Custom Properties and Theming
More than one color and property. It's not only colors that can change, a Custom Property can be any valid value. Here's Keith...
Read more >A Strategy Guide To CSS Custom Properties
If --user-theme-color is not set, the value of #d33a2c will be used. This way, we don't need to provide a fallback every time...
Read more >I Finally Implemented Dark Mode Using CSS Custom ...
I replaced the majority of color , background-color , and border-color properties with CSS custom properties. And, finally, I added the ability ...
Read more >Two options for using custom properties - QuirksBlog
We discussed CSS custom properties, and something interesting happened. ... the colour values in the component styles without using custom ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@okonet - got and i believe your issue would be fixed by #1327 - where the css custom variables are only updated on the body tag. This way the individual components styles should not change and emotion should not create new classes on color mode change.
we would really appreciate if you can try it out and let us know, i haven’t specifically done the tests that you have
@atanasster hmm, let me try the latest beta. I’m on the latest stable version: 3.5.0 and this is still an issue.
I do understand why you’d like to rely on the React context here, but I also am confused why is there the need to pre-render all CSS custom properties then. That’s why I raised this question. To me having them in DOM should eliminate the need to rely on the context but it looks like I’m mistaken?