fix: drive kit color mode from darkMode prop, ignore localStorage#613
Conversation
Chakra v2's ColorModeProvider inside the kit reads localStorage["chakra-ui-color-mode"] in a mount-time effect and overwrites its internal state with that stale value, ignoring the `darkMode` prop. The old ColorModeSync compared the *initial* colorMode against the target before Chakra's effect ran, so it never corrected the drift. React 19 / Next.js 16 strict mode makes this race deterministic — light mode is now permanently broken in hosts that previously rendered the kit in dark mode. Replace ColorModeScript + ColorModeSync with a custom colorModeManager that always reports the current darkMode prop and no-ops writes. Recreating the manager when darkMode changes re-triggers Chakra's read effect, so the internal color mode now tracks the prop without ever touching localStorage. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR refactors Chakra color-mode handling in ChangesTheme Color-Mode Unification
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🚀 Preview environment deployed! |
|
Size Change: +56 B (0%) Total Size: 8.47 MB
ℹ️ View Unchanged
|
Summary
ColorModeProviderinside the kit readslocalStorage["chakra-ui-color-mode"]in a mount-time effect and overwrites its internal state with that stale value, ignoring thedarkModeprop. The oldColorModeSynccompared the initialcolorModeagainst the target before Chakra's effect ran, so it never corrected the drift.ColorModeScript+ColorModeSyncwith a customcolorModeManagerpassed toChakraProviderthat always reports the currentdarkModeprop value and no-ops writes. The manager's identity is keyed ondarkMode, so a flip re-triggers Chakra's read effect and the internal color mode tracks the prop without ever touchinglocalStorage.Closes #608
Summary by CodeRabbit
Release Notes
Refactor
Breaking Changes