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.

1.0.0-rc.5 refuses to start in dark mode inside of Storybook

See original GitHub issue

Bug report

Chakra-ui 1.0.0-rc.5 seems to be ignoring:

  • theme.config.initialColorMode set to dark
  • <ChakraProvider>'s initialColorMode property set to dark

Even tough i set initialColorMode to dark on my theme or ChakraProvider mode to dark on my theme Chakra seems to be overwriting the colorMode with an empty string.

The theme used in this example was downloaded from chakra-ui repository.

To reproduce

I have created a repository with only storybook and chakra-ui 1.0.0-rc.5

git clone https://github.com/hems/chakra-storybook-problem
cd chakra-storybook-problem
y install
y storybook

Once storybook is open, check the console and you will see the following console logs:

image

First one is provided by the ChakraProvider decorator on Storybook, you can see it on this file on line 16

export const Chakra = ({ children }) => {
  console.log("theme.config ->", newTheme.config)
  
  return (
    <ChakraProvider CSSReset theme={newTheme} initialColorMode="dark">
      <Box p={5}>
        {children}
      </Box>
    </ChakraProvider>
  )
}

The two other logs are useColorMode hook crated on this component

const Welcome = ({showApp}) => {
  const { colorMode } = useColorMode();

  console.log('got colormode ->', colorMode)

  return (
    <>
      <Box>
        This is a custom welcome message using Chakra UI
      </Box>
      <Link onClick={showApp} color="teal.500">
        Let's go to see the button
      </Link>
    </>
  )
}

Expected behavior

Chakra component to be rendered using dark theme, no the light theme

Screenshots

image

Additional context

  • I have noted in a previous RC version that there was a localStorage value called ui-color-theme or similar and a second render was happening with such value, but on this RC-5 version i can’t find that variable and i’m not sure if that’s somehow related.

  • wrapping the component with <DarkMode> doesn’t seem to work as well.

  • Navigating to another button on the storybook and then coming back to the original story will show two renders, one with dark mode and another with light mode right after, which i believe demonstrates Chakra is override the colorMode at some point?

image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ljosberinncommented, Oct 20, 2020

No worries, glad it worked out 😃 personally wasn’t aware of that file either. Good to know!

1reaction
hemscommented, Oct 20, 2020

Turns out what solved my issue was adding the preview-head.html copied from the Chakra storybook.

( :

And apologies about the extra props on the ChakraProvider, that was me naively trying some props that showed up on my auto complete.

Read more comments on GitHub >

github_iconTop Results From Across the Web

storybook-dark-mode Addon
storybook -dark-mode. A storybook addons that lets your users toggle between dark and light mode. Example. Installation. Install the following npm module:
Read more >
Storybook React with Dark Mode Option - David Yeiser
To begin, make a new directory called storybook-react-with-dark-mode wherever you normally put your development projects.
Read more >
2021 DODGE DURANGO OWNER'S MANUAL
the driver's door is open, the doors will not lock. If a rear door is locked, it cannot be opened from inside the...
Read more >
HL7 Version 2.5.1 Implementation Guide: Immunization ... - CDC
1 Implementation Guide for. Immunization Messaging. Revision history. Revision. Date. Author. Release 1.0. 5/1/2010.
Read more >
bzi - River Thames Conditions - Environment Agency - GOV.UK
Armageddon movie demands, Ledeganck auditorium 5, 531 pill red, ... Eafit proteine avis, Patapon 3 dark hero mode gameplay, Kang in ho prime...
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