Skip to content

fix(react): resolve theme toggle hydration mismatch - #1103

Merged
bmuenzenmeyer merged 3 commits into
nodejs:mainfrom
puneetnith28:fix/theme-toggle-hydration
Oct 27, 2026
Merged

bmuenzenmeyer merged 3 commits into
nodejs:mainfrom
puneetnith28:fix/theme-toggle-hydration

Conversation

@puneetnith28

Copy link
Copy Markdown
Contributor

Description

Fixes a hydration mismatch where the ThemeToggle icon resets to the system icon after page reload when a user preference (dark / light) is stored.

Changes

  • Initialized pref state to 'system' by default in useTheme.mjs to ensure server HTML and client initial render match.
  • Synchronized pref with localStorage inside a useEffect hook on client mount.
  • Added key={themePreference} to <ThemeToggle> to ensure clean remounting when the theme preference is applied.

References

@puneetnith28
puneetnith28 requested a review from a team as a code owner September 15, 2026 21:18
@vercel

vercel Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
api-docs-tooling Ready Ready Preview Sep 16, 2026 10:49am UTC

Request Review

@puneetnith28

Copy link
Copy Markdown
Contributor Author

Please review this PR and let me know if any further changes are needed.
Thanks!!

@puneetnith28
puneetnith28 requested a review from ryzrr September 16, 2026 11:03
@ryzrr

ryzrr commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

LGTM !

@bmuenzenmeyer bmuenzenmeyer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with aviv - but not enough to block this. its broken in production right now and we should make this better.

thanks!

@bmuenzenmeyer
bmuenzenmeyer merged commit e3b0793 into nodejs:main Oct 27, 2026
1 check passed

This branch was successfully deployed

1 active deployment
Preview – api-docs-tooling — e12d85a3 Deployed Sep 16, 2026 by vercel[bot]
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.

6 participants