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.

When I implement `ColorModeScript` set to `useSystemColorMode: true` and `initialColorMode: "dark"` it does not seem to be working.

See original GitHub issue

Description

When I implement ColorModeScript set to useSystemColorMode: true and initialColorMode: "dark" it does not seem to be working.

Link to Reproduction

https://github.com/jcstein/buildmarket-lol

Steps to reproduce

  1. Go to https://github.com/jcstein/buildmarket-lol
  2. Clone the repo
  3. Run yarn
  4. Run yarn start
  5. See error

Chakra UI Version

2.2.1

Browser

Brave/Safari/Firefox

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

https://buildmarket.lol

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
itkrt2ycommented, Jun 21, 2022

@jcstein

@chakra-ui/color-mode seems to have changed the behavior of the initial color in v2.0.0 https://github.com/chakra-ui/chakra-ui/releases/tag/%40chakra-ui%2Fcolor-mode%402.0.0

If user specifies useSystemColorMode: true, then we’ll subscribe to color mode changes from the operating system. It is no longer used to determine the initial color mode. To achieve that, please use initialColorMode: "system"

Therefore, if you’d like to use the system color as the default color, fix theme as follows.

// src/theme.ts

const config: ThemeConfig = {
-  initialColorMode: "dark",
+  initialColorMode: "system",
  useSystemColorMode: true,
};

And there is a bug in https://github.com/jcstein/buildmarket-lol. You need to pass a custom theme to ChakraProvider instead of the default theme.

// src/App.tsx

import {
  ChakraProvider,
  Box,
  Text,
  Link,
  VStack,
  Code,
  Grid,
-  theme,
  Button,
} from "@chakra-ui/react";
import { ColorModeSwitcher } from "./ColorModeSwitcher";
import { Logo } from "./Logo";
import { FaRobot } from "react-icons/fa";
+ import theme from "./theme";

export const App = () => (
  <ChakraProvider theme={theme}>
1reaction
jcsteincommented, Jun 21, 2022

thank you so much! @itkrt2y

Read more comments on GitHub >

github_iconTop Results From Across the Web

Color Mode - Chakra UI
Add the ColorModeScript to your application, and set the initial color mode your application should start with to either light , dark or...
Read more >
Chakra UI color mode changes on page refresh, because of ...
I'm running NextJS with Chakra UI and the problem is when useSystemColorMode is set to true ...
Read more >
Color Mode - Chakra UI
When you use the ChakraProvider at the root of your app, you can automatically use color mode in your apps. By default, most...
Read more >
What is Dark Mode for Email and Does it Affect Rendering?
Dark mode is a setting that shifts an interface's color palette to display content in high contrast using dark background colors and light...
Read more >
@chakra-ui/provider - npm
If you are not sure why you are using it, please use @chakra-ui/react ... useSystemColorMode: false, // or true initialColorMode: "light", ...
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