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.

[ColorModeProvider] Color mode does not work in production

See original GitHub issue

Describe the bug Switching between dark and light mode is not working in production build.

Expected Behavior After clicking on the color mode switcher button it should be switching theme colors between light and dark.

To Reproduce I am using chakra-ui with gatsby with below mentioned versions: "gatsby": "^2.18.8", "gatsby-plugin-chakra-ui": "^0.1.0",

code <ThemeProvider theme={theme}> <CSSReset /> <ColorModeProvider> <Header siteTitle={data.site.siteMetadata.title} /> <main>{children}</main> <Footer /> </ColorModeProvider> </ThemeProvider>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:20 (8 by maintainers)

github_iconTop GitHub Comments

8reactions
KenzoBenzocommented, Jan 23, 2020

Hey @amolmt & @MykalMachon! I’ve got it working successfully working for Gatsby. The trick is that the root of Gatsby is gatsby-browser.js. So the code I’ve got is:

import React from "react"
import { ThemeProvider, ColorModeProvider, CSSReset } from "@chakra-ui/core"
import theme from "./theme/theme"

export const wrapRootElement = ({ element }) => (
  <ThemeProvider theme={theme}>
    <ColorModeProvider>
      <CSSReset />
      {element}
    </ColorModeProvider>
  </ThemeProvider>
)

If you need further reference, my personal portfolio repo is public, here.

3reactions
MykalMachoncommented, Dec 22, 2019

Hello @amolmt, I think this is more an issue with Gatsby (specifically, React) than it is with Chakra-UI.

I’ve experienced bugs similar to this one myself when using gatsby. From what I know it has to do with the way Gatsby implements React’s rehydrate method on statically generated pages. You can read more about it here and here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gatsby w/ Chakra UI ColorMode not working - Stack Overflow
I'm using Gatsby w/ Chakra UI and have an issue with either local storage or how the ColorMode is being accessed.
Read more >
Color Mode - Chakra UI
Color Mode. Chakra UI comes with built-in support for managing color mode in your apps. By default, most of Chakra's components are dark...
Read more >
Advanced techniques in Chakra UI - LogRocket Blog
colorMode is the current color mode, and toggleColorMode is the function to toggle the color mode. We pass the toggleColorMode function to the ......
Read more >
Upgrading to v1 - Chakra UI
ColorModeProvider : Provides color mode (light or dark) context to all components. ... You can skip this if you are not already using...
Read more >
Designing and implementing dark mode on a website
Dark mode or light-on-dark color scheme is a new popular trend in user interface ... Adding the third auto option solves this problem....
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