Skip to content

fix(web): eliminate dark mode white flash on initial page load#313

Open
KaparthyReddy wants to merge 1 commit into
Dev-Card:mainfrom
KaparthyReddy:fix/dark-mode-flash-clean
Open

fix(web): eliminate dark mode white flash on initial page load#313
KaparthyReddy wants to merge 1 commit into
Dev-Card:mainfrom
KaparthyReddy:fix/dark-mode-flash-clean

Conversation

@KaparthyReddy
Copy link
Copy Markdown

Summary

Eliminates the dark mode white flash on initial page load. Previously, the theme was applied inside onMount in +page.svelte, which runs after first paint — causing a brief white flash for dark mode users on hard refresh or slow page loads. This PR adds a blocking inline IIFE script to <head> in app.html that reads localStorage('devcard-theme') and falls back to window.matchMedia('prefers-color-scheme: dark') to apply the .dark class to <html> before any content renders.

Closes #91


Type of Change

  • Bug fix
  • New feature
  • Refactor (no functional change)
  • UI / Design change
  • Tests only
  • Documentation
  • Infrastructure / DevOps
  • Security

What Changed

  • apps/web/src/app.html — Added a blocking synchronous IIFE script in <head> that reads localStorage('devcard-theme') and falls back to window.matchMedia('prefers-color-scheme: dark'), applying .dark to <html> before first paint. Wrapped in try/catch for private browsing resilience.

How to Test

  1. Open the app and set theme to dark using the 🌙 toggle
  2. Hard refresh (Cmd+Shift+R) — page should load dark instantly with no white flash
  3. Open DevTools → Application → Local Storage → delete devcard-theme
  4. Hard refresh — should still load dark (system preference fallback)
  5. Set devcard-theme to light in localStorage, hard refresh — should load light with no flash

Checklist

  • My code follows the project's coding style (pnpm -r run lint passes).
  • TypeScript compiles without errors (pnpm -r run typecheck).
  • I have added or updated tests for the changes I made.
  • All tests pass locally (pnpm -r run test).
  • I have updated documentation where necessary.
  • No new console.log or debug statements left in the code.
  • Breaking changes are documented in this PR description.

Screenshots / Recordings

Light mode (devcard-theme=light):
image

Dark mode (devcard-theme=dark):
image

Both load instantly with correct theme — no white flash on hard refresh.


Additional Context

Only apps/web/src/app.html was modified. No changes to component logic, styles, or other files. The existing onMount theme toggle in +page.svelte continues to handle runtime theme switching — this script only ensures the correct initial state is set before first paint.

The backend test failures (event.test.ts) are pre-existing and unrelated to this change — they fail identically on main without our modification. Our change only touches apps/web/src/app.html.

Add blocking inline IIFE script to <head> in app.html that reads
localStorage('devcard-theme') and falls back to window.matchMedia
to apply the .dark class to <html> before any content renders.

Previously, the theme was applied inside onMount in +page.svelte,
which runs after first paint — causing a visible white flash for
dark mode users on hard refresh or slow page loads.

Closes Dev-Card#91
@Harxhit Harxhit added the gssoc:approved Required label for every approved PR. Gives the base +50 points and enables contribution tracking. label May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Required label for every approved PR. Gives the base +50 points and enables contribution tracking.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Dark mode users see a white flash on page load

2 participants