fix(web): remove the header theme-toggle icon flicker on first load#153
Merged
Conversation
The toggle gated its icon on a `mounted` state and rendered an empty placeholder until the client mounted, because next-themes keeps the theme in localStorage where the server can't read it — so the icon popped in a beat after first paint. The selected theme is now mirrored to a cookie, read in the root layout, and seeded into the toggle so SSR and hydration draw the same icon with no mount gate, no flicker, and no hydration mismatch. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: a106c32 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
size-limit report 📦
|
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #153 +/- ##
=======================================
Coverage 84.29% 84.29%
=======================================
Files 70 70
Lines 1248 1248
Branches 293 293
=======================================
Hits 1052 1052
Misses 119 119
Partials 77 77
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Remove the header theme-toggle icon flicker on first load.
Why
The toggle gated its icon on a
mountedstate and rendered an empty placeholder until the client mounted. next-themes keeps the theme in localStorage, which the server can't read, so the icon could not be server-rendered and popped in a beat after first paint. This is the standard next-themes anti-mismatch pattern, traded for a flicker.How
The selected theme is mirrored into a cookie whenever it changes, read in the root layout (a server component) via
cookies(), and seeded into the toggle through a smallInitialThemeProvider. SSR and the first client render now draw the same icon, so the mount gate is gone: no flicker and no hydration mismatch. The cookie and localStorage are kept in sync, and a returning user whose cookie was absent converges once on mount.Impact
@flemo/webpatch. No library change.Test plan
pnpm --filter @flemo/web typecheck lint buildgreen.Rollback
Revert the squash merge.