[Bug] Color mode in local storage not working after navigation or refresh
See original GitHub issueDescription
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
- In the code sandbox, toggle color mode to ‘light’ with the button on index page.
- Now local storage should have an item like ‘chakra-ui-color-mode: light’.
- Navigate to another page with the link on index page.
- 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
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.
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
@aboveyunhai Solved! Thanks a lot!