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.

initialColorMode in gatsby-plugin-theme-ui not working

See original GitHub issue

When 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:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
kevinwolfcrcommented, Oct 10, 2019

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:

  1. After adding the useColorSchemeMediaQuery prop to my theme, I’d cleared my localStorage and refreshed, it matched my dark system preferences.
  2. I’d changed my system preferences to light, went back to the site and refreshed, but the site UI was still on dark theme.

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.

3reactions
mcs07commented, Nov 16, 2019

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, if useColorSchemeMediaQuery: 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. by setColorMode(null) clearing the local storage.

Read more comments on GitHub >

github_iconTop 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 >

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