New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code runs twice after adding useColorModeValue hook #5046
Comments
Hi @justnoobbot this is not a bug, it's working as designed by React. |
@anubra266 I believe this is the color mode issue that was just fixed by #4989. If the system color mode is dark then the app is rendered with the initialColor mode, light. It then re-renders with dark mode. Using the CSB with the fix, the example that was provided only renders once for light mode. |
A new version has been released @justnoobbot which includes the fix |
@anubra266 I just updated |
cc @primos63 |
In the mean time you can use the |
My apologies. I missed the notification on this. I looked at the CSB, what am I suppose to observe? I ran the app with and without the commented out code. Each time the log, modified to Uncommenting the code, |
@primos63 try it in dark mode |
I did. In light mode the text is black and bg white. In dark mode the bg is dark gray and text is white. What am I suppose to be seeing? |
@primos63 Check the console in dark mode, the component is rendered twice. |
@anubra266 Thanks. I just finished triaging the issue. This is the white flash/double render issue caused by the ColorModeManager. I've tested a local fix with a React app and will follow up with one using Next. Once that's complete I'll submit a PR. |
Hi! |
Description
When I run the app i expect console.log("log") to run once, but it got executed twice
Link to Reproduction
https://codesandbox.io/s/chakra-ui-usecolormodevalue-j5y1j?file=/src/App.js
Steps to reproduce
console.log("log");
got executed twiceWhen I remove
const bg = useColorModeValue("white", "gray");
it runs once as expected(I need that in my project)
Chakra UI Version
1.6.12
Browser
No response
Operating System
Additional Information
No response
The text was updated successfully, but these errors were encountered: