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.

[Bug] Color mode in local storage not working after navigation or refresh

See original GitHub issue

Description

I set initialColorMode = 'dark'. When I manually selected my preferred color mode to 'light', local storage did remembered my selection; but after a page refresh or navigation, the color mode returned to ‘dark’, although local storage did indicate chakra-ui-color-mode === 'light'.

Link to Reproduction

https://codesandbox.io/s/competent-firefly-obu73s

Steps to reproduce

  1. In the code sandbox, toggle color mode to ‘light’ with the button on index page.
  2. Now local storage should have an item like ‘chakra-ui-color-mode: light’.
  3. Navigate to another page with the link on index page.
  4. The color mode returns to ‘dark’.

Chakra UI Version

1.8.8

Browser

Microsoft Edge (100.0.1185.50) (64-bit)

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

image

When I set breakpoint to watch on every attribute change on html element, I saw the style attr was always --chakra-ui-color-mode:dark, but the data-theme attr switched from ‘light’ to ‘dark’ on the 3rd break.

image

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
aboveyunhaicommented, Apr 28, 2022

@mrcaidev can confirm is a bug related to Chakra with the latest react 18 version. If you revert back to react@17.0.2 react-dom@17.0.2 (the latest v17). Everything should work as expect. Since the newest React version does not significantly improve Chakra UI, I would just recommend you stick with react v17, wait few more minor versions until it’s stable to upgrade or the bug is fixed. You are going to use other packages anyway, all of React-related packages are also facing the same migration issues most likely.

0reactions
mrcaidevcommented, Apr 28, 2022

@aboveyunhai Solved! Thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chakra UI color mode changes on page refresh, because of ...
I'm running NextJS with Chakra UI and ...
Read more >
How to Fix Divi - A Complete Guide To Solve Issues and ...
#1. Clear Your Cache (Especially After Every Update). Cache is files and resources that are stored locally in a browser or network to...
Read more >
Issues: Find and fix problems - Chrome Developers
Visit a page with issues to fix, such as samesite-sandbox.glitch.me. · Open DevTools. · Click the Open Issues button next to Settings. ·...
Read more >
Visual Studio 2022 Release Notes | Microsoft Learn
Get the latest features, bug fixes, and support for Visual Studio 2022. Download today.
Read more >
Configure your browser for Figma
In the System section, enable Use hardware acceleration when available; If WebGL isn't enabled, open Chrome's Flags settings chrome://flags/ . Update the ...
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