Skip to content

fix: drive kit color mode from darkMode prop, ignore localStorage#613

Merged
Agilulfo1820 merged 1 commit into
mainfrom
fix/color-mode-sync-with-host
May 14, 2026
Merged

fix: drive kit color mode from darkMode prop, ignore localStorage#613
Agilulfo1820 merged 1 commit into
mainfrom
fix/color-mode-sync-with-host

Conversation

@Agilulfo1820

@Agilulfo1820 Agilulfo1820 commented May 14, 2026

Copy link
Copy Markdown
Member

Summary

  • 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 16 strict mode makes the effect ordering deterministic, so light mode is now permanently broken in hosts that previously rendered the kit in dark mode (e.g. Next 16 + Chakra v3 + next-themes apps like b3tr). Before Next 16, a refresh sometimes recovered.
  • Replace ColorModeScript + ColorModeSync with a custom colorModeManager passed to ChakraProvider that always reports the current darkMode prop value and no-ops writes. The manager's identity is keyed on darkMode, so a flip re-triggers Chakra's read effect and the internal color mode tracks the prop without ever touching localStorage.

Closes #608

Summary by CodeRabbit

Release Notes

  • Refactor

    • Simplified theme color-mode handling to provide more reliable control and consistency across the application. Theme configuration is now unified and centrally managed.
  • Breaking Changes

    • Removed an internal theming component that is no longer necessary with the refactored approach.

Review Change Stack

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]>
@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR refactors Chakra color-mode handling in VechainKitThemeProvider.tsx to unify control around the darkMode prop by introducing a colorModeManager that reports mode based on the prop and disables localStorage access, removing prior SSR detection and effect-based synchronization.

Changes

Theme Color-Mode Unification

Layer / File(s) Summary
Contract and import updates
packages/vechain-kit/src/providers/VechainKitThemeProvider.tsx
Import list removes useEffect and the SSR query helper safeQuerySelector. EnsureChakraProvider props are extended to accept a colorModeManager parameter for Chakra color-mode control.
Provider wiring and color-mode implementation
packages/vechain-kit/src/providers/VechainKitThemeProvider.tsx
EnsureChakraProvider is wired to pass colorModeManager to ChakraProvider and removes the SSR helper flow. VechainKitThemeProvider introduces a prop-driven colorModeManager that derives mode from darkMode and passes it to EnsureChakraProvider, replacing prior render paths with EnsureColorModeScript and ColorModeSync.
Remove obsolete ColorModeSync component
packages/vechain-kit/src/providers/VechainKitThemeProvider.tsx
The exported ColorModeSync component is removed; it previously used useColorMode and useEffect to reconcile Chakra color mode with the darkMode prop.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A color mode manager springs to life,
No effects or queries—just the prop takes the knife,
Dark and light dance where the darkMode is true,
No localStorage whispers, the refactor rings new!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: refactoring color mode handling to be driven by the darkMode prop while preventing localStorage interference.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/color-mode-sync-with-host

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Agilulfo1820 Agilulfo1820 merged commit b1b02c3 into main May 14, 2026
6 of 7 checks passed
@Agilulfo1820 Agilulfo1820 deleted the fix/color-mode-sync-with-host branch May 14, 2026 15:47
@github-actions

Copy link
Copy Markdown
Contributor

@github-actions

Copy link
Copy Markdown
Contributor

Size Change: +56 B (0%)

Total Size: 8.47 MB

Filename Size Change
packages/vechain-kit/dist/index-BsFRkVCC.d.cts 0 B -170 kB (removed) 🏆
packages/vechain-kit/dist/index-BsFRkVCC.d.cts.map 0 B -46.8 kB (removed) 🏆
packages/vechain-kit/dist/index-C8Uj8ple.d.cts 0 B -5.63 kB (removed) 🏆
packages/vechain-kit/dist/index-C8Uj8ple.d.cts.map 0 B -2.99 kB (removed) 🏆
packages/vechain-kit/dist/index-DWD9OpXd.d.mts 0 B -5.63 kB (removed) 🏆
packages/vechain-kit/dist/index-DWD9OpXd.d.mts.map 0 B -2.99 kB (removed) 🏆
packages/vechain-kit/dist/index-MhYunXpj.d.mts 0 B -170 kB (removed) 🏆
packages/vechain-kit/dist/index-MhYunXpj.d.mts.map 0 B -46.8 kB (removed) 🏆
packages/vechain-kit/dist/index-Bekk3wer.d.cts 5.63 kB +5.63 kB (new file) 🆕
packages/vechain-kit/dist/index-Bekk3wer.d.cts.map 2.99 kB +2.99 kB (new file) 🆕
packages/vechain-kit/dist/index-BOUE7zYM.d.cts 170 kB +170 kB (new file) 🆕
packages/vechain-kit/dist/index-BOUE7zYM.d.cts.map 46.8 kB +46.8 kB (new file) 🆕
packages/vechain-kit/dist/index-BYfc-9J5.d.mts 5.63 kB +5.63 kB (new file) 🆕
packages/vechain-kit/dist/index-BYfc-9J5.d.mts.map 2.99 kB +2.99 kB (new file) 🆕
packages/vechain-kit/dist/index-CGb6z0q_.d.mts 170 kB +170 kB (new file) 🆕
packages/vechain-kit/dist/index-CGb6z0q_.d.mts.map 46.8 kB +46.8 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size
packages/vechain-kit/dist/assets 4.1 kB
packages/vechain-kit/dist/assets-BL24r-Yp.mjs 51.3 kB
packages/vechain-kit/dist/assets-BL24r-Yp.mjs.map 74.1 kB
packages/vechain-kit/dist/assets-DNJsQD7_.cjs 58.5 kB
packages/vechain-kit/dist/assets-DNJsQD7_.cjs.map 75.5 kB
packages/vechain-kit/dist/assets/index.cjs 716 B
packages/vechain-kit/dist/assets/index.d.cts 973 B
packages/vechain-kit/dist/assets/index.d.mts 973 B
packages/vechain-kit/dist/assets/index.mjs 718 B
packages/vechain-kit/dist/index.cjs 1.11 MB
packages/vechain-kit/dist/index.cjs.map 2.69 MB
packages/vechain-kit/dist/index.d.cts 22.8 kB
packages/vechain-kit/dist/index.d.mts 22.8 kB
packages/vechain-kit/dist/index.mjs 1.07 MB
packages/vechain-kit/dist/index.mjs.map 2.63 MB
packages/vechain-kit/dist/utils 4.1 kB
packages/vechain-kit/dist/utils-DJKLAzLP.cjs 27.2 kB
packages/vechain-kit/dist/utils-DJKLAzLP.cjs.map 67.2 kB
packages/vechain-kit/dist/utils-KYzX9d5n.mjs 22.1 kB
packages/vechain-kit/dist/utils-KYzX9d5n.mjs.map 66.5 kB
packages/vechain-kit/dist/utils/index.cjs 1.98 kB
packages/vechain-kit/dist/utils/index.d.cts 3.04 kB
packages/vechain-kit/dist/utils/index.d.mts 3.04 kB
packages/vechain-kit/dist/utils/index.mjs 2 kB

compressed-size-action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 issues with black theme on b3tr

1 participant