initialColorMode in gatsby-plugin-theme-ui not working
See original GitHub issueWhen using the gatsby-plugin-theme-ui
plugin with Gatsby, it is not using the initialColorMode
in the /src/gatsby-plugin-theme-ui/index.js
file, and instead, it is using the dark
mode directly.
Take this theme as an example:
export default {
initialColorMode: 'light',
colors: {
text: '#000',
background: '#fff',
primary: '#6e67ff',
secondary: '#212121',
modes: {
dark: {
text: '#fff',
background: '#212121',
secondary: '#fff',
},
},
},
};
It should use the light mode as the default mode, but instead, it is using the dark
mode with no reason.
Here is a reproduction of the issue: https://codesandbox.io/embed/gatsby-starter-default-qyqkp
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Color Mode
Working with color mode (light and dark mode) in Chakra UI. ... be used as default - initialColorMode is the fallback if system...
Read more >Chakra UI color mode changes on page refresh, because ...
What I expect is the initial color mode to be the system color mode (in my case = dark) and when the user...
Read more >Color Mode
Working with color mode (light and dark mode) in Chakra UI. ... a user upfront so you can avoid rendering the initial color...
Read more >How to add dark mode toggle to Next.js application using ...
For Chakra UI to work correctly, you need to set up the ... config which sets the initial color mode to light and...
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 Free
Top 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
Thanks @jxnblk, adding that to my theme solved the issue. Although I have a recommendation: the theme should always be in sync with the system preferences, this is what just happened to me:
useColorSchemeMediaQuery
prop to my theme, I’d cleared my localStorage and refreshed, it matched my dark system preferences.Is this an expected behaviour? IMHO it should change according to the system preferences, and only save into localStorage if the user explicitly set so.
I agree with the comment by @iamkevinwolf. My preferred behaviour would be localStorage would never be set until and unless
setColorMode
was explicitly called. And also, ifuseColorSchemeMediaQuery: true
then ideally the color mode would dynamically update as the system preference changes from dark to light, without a refresh. It would also be nice to be able to reset the color mode back to ‘auto’ after choosing light/dark, e.g. bysetColorMode(null)
clearing the local storage.