Skip to content

fix(theme): eliminate dark-mode first-paint flash#10

Open
yyyr-p wants to merge 1 commit into
dimthink:mainfrom
yyyr-p:fix/theme-first-paint-flash
Open

fix(theme): eliminate dark-mode first-paint flash#10
yyyr-p wants to merge 1 commit into
dimthink:mainfrom
yyyr-p:fix/theme-first-paint-flash

Conversation

@yyyr-p

@yyyr-p yyyr-p commented Jul 20, 2026

Copy link
Copy Markdown

Summary

  • Move the theme-init IIFE from next/script beforeInteractive into a native synchronous <head><script> that executes at HTML parse time — before the browser reaches <body> and its first style calculation
  • Extract the shared priceai-theme localStorage key into a single THEME_STORAGE_KEY constant so the reader (init script) and writer (ThemeToggle) cannot drift silently
  • Add a node:vm decision-matrix test covering 11 scenarios (stored preference priority, system preference fallback, /admin forced light, localStorage/matchMedia errors, inline-script safety)

Verification

  • npm run test:theme-init — 11 cases pass
  • npm test — full suite passes
  • npm run typecheck — clean
  • npm run lint — clean (1 pre-existing unrelated warning)
  • npm run build — production build succeeds
  • Chrome DevTools (Slow 3G + 6× CPU + system light + stored dark): hard refresh, direct URL, new tab all render dark on first visible frame with no transition flash; /admin remains light; ThemeToggle preserves its existing color transition animation

Move the theme-init IIFE from next/script beforeInteractive (which
defers execution to the client bootstrap) into a native synchronous
<head><script> that runs at HTML parse time — before the browser
reaches <body> and its first style calculation.

Extract the shared localStorage key into a single THEME_STORAGE_KEY
constant so the reader (init script) and writer (ThemeToggle) cannot
drift silently.

Add a node:vm decision-matrix test covering 11 scenarios (stored
preference priority, system preference fallback, /admin forced light,
localStorage/matchMedia errors, inline-script safety).
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