Skip to content

fix(web): remove the header theme-toggle icon flicker on first load#153

Merged
kimjh96 merged 2 commits into
mainfrom
fix/theme-icon-flicker
Jul 2, 2026
Merged

fix(web): remove the header theme-toggle icon flicker on first load#153
kimjh96 merged 2 commits into
mainfrom
fix/theme-icon-flicker

Conversation

@kimjh96

@kimjh96 kimjh96 commented Jun 30, 2026

Copy link
Copy Markdown
Owner

What

Remove the header theme-toggle icon flicker on first load.

Why

The toggle gated its icon on a mounted state 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 small InitialThemeProvider. 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/web patch. No library change.

Test plan

  • pnpm --filter @flemo/web typecheck lint build green.
  • Verify on first load (and repeated reloads) that the theme icon no longer pops in; toggling through system/light/dark persists across reloads with the correct icon from the first paint.

Rollback

Revert the squash merge.

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-bot

changeset-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a106c32

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@flemo/web Patch

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

@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
flemo-web Ready Ready Preview, Comment Jul 2, 2026 3:59pm

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
@flemo/core 11.61 KB (0%)
@flemo/react 7.09 KB (0%)
@flemo/react-layout 552 B (0%)

@pkg-pr-new

pkg-pr-new Bot commented Jun 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@flemo/core@153
npm i https://pkg.pr.new/@flemo/react@153
npm i https://pkg.pr.new/@flemo/react-layout@153

commit: a106c32

@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.29%. Comparing base (951bde1) to head (a106c32).

Additional details and impacted files

Impacted file tree graph

@@           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           
Flag Coverage Δ
unittests 84.29% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kimjh96 kimjh96 merged commit 15172f6 into main Jul 2, 2026
12 checks passed
@kimjh96 kimjh96 deleted the fix/theme-icon-flicker branch July 2, 2026 16:02
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.

1 participant