Skip to content

fix: prevent light-mode flash on initial page load#187

Closed
dobby-coder[bot] wants to merge 1 commit into
mainfrom
fix/issue-180-dark-mode-flash
Closed

fix: prevent light-mode flash on initial page load#187
dobby-coder[bot] wants to merge 1 commit into
mainfrom
fix/issue-180-dark-mode-flash

Conversation

@dobby-coder

@dobby-coder dobby-coder Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds a small synchronous inline script to src/app.html that applies the .dark class to <html> before the browser paints, eliminating the brief light-mode flash on refresh while in dark mode.
  • The script reads the same sources as ThemeSwitcher.svelte: localStorage['preferredtheme'] first, falling back to prefers-color-scheme: dark.

Why

Theme was only applied during Svelte hydration (in ThemeSwitcher.svelte's top-level browser block). Because the static HTML is delivered without the dark class, the page paints with light defaults until JS runs — a classic FOUC.

A blocking <script> in <head> runs before first paint, so the .dark class is on <html> before any styles resolve. ThemeSwitcher.svelte keeps working unchanged (its own classList.toggle on hydration is now a no-op confirmation).

Test plan

  • npm run build — success
  • npm run check — 0 errors, 0 warnings
  • Verified the inline script lands in built index.html
  • Manual verification: set system to dark / pick dark in switcher, refresh — no light flash

Reviewer quickstart

git fetch origin && git checkout fix/issue-180-dark-mode-flash && npm install --legacy-peer-deps && npm run dev

Closes #180

Add a synchronous inline script in app.html that reads the user's theme
preference (localStorage 'preferredtheme', falling back to
prefers-color-scheme) and applies the .dark class to <html> before the
browser paints. Previously the class was only set during Svelte
hydration, causing a brief light-mode flash on every refresh in dark
mode.

Closes #180
@dobby-coder dobby-coder Bot requested a review from rubenhensen May 9, 2026 13:37
@dobby-coder dobby-coder Bot marked this pull request as ready for review May 9, 2026 13:39
@dobby-coder

dobby-coder Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #202 (consolidation per encryption4all/dobby#53). Closing to keep the queue tidy.

@dobby-coder dobby-coder Bot closed this May 9, 2026
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.

Super quick "light-mode" flash

0 participants