fix: prevent light-mode flash on initial page load#187
Closed
dobby-coder[bot] wants to merge 1 commit into
Closed
Conversation
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
This was referenced May 9, 2026
Contributor
Author
|
Superseded by #202 (consolidation per encryption4all/dobby#53). Closing to keep the queue tidy. |
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.
Summary
src/app.htmlthat applies the.darkclass to<html>before the browser paints, eliminating the brief light-mode flash on refresh while in dark mode.ThemeSwitcher.svelte:localStorage['preferredtheme']first, falling back toprefers-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 thedarkclass, the page paints with light defaults until JS runs — a classic FOUC.A blocking
<script>in<head>runs before first paint, so the.darkclass is on<html>before any styles resolve.ThemeSwitcher.sveltekeeps working unchanged (its ownclassList.toggleon hydration is now a no-op confirmation).Test plan
npm run build— successnpm run check— 0 errors, 0 warningsindex.htmlReviewer quickstart
Closes #180