fix(viewer): apply saved theme before first paint to stop dark-mode flash#10
Merged
Conversation
Deploying caveviewer with
|
| Latest commit: |
82a4a60
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://963eb0b9.caveviewer.pages.dev |
| Branch Preview URL: | https://fix-theme-label-fouc.caveviewer.pages.dev |
…lash A light-mode reload briefly painted the default dark theme because the theme was only applied by the deferred app bundle, after first paint. Apply the saved theme to <html> from a tiny same-origin script loaded blocking in <head>, before the bundle. No CSP change needed: script-src 'self' already covers it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
17bb521 to
82a4a60
Compare
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.
Problem
On reload, a light-mode user saw the whole page flash dark before snapping to light. The theme was only applied by the deferred app bundle (
main.ts), which runs after first paint, while the CSS:rootdefault is dark.Fix
Apply the saved theme to
<html>before first paint, from a tiny same-origin script (public/theme-init.js) loaded as a blocking<script>in<head>— ahead of the deferred bundle.main.tsstill owns the theme at runtime; this only sets the initial attribute.script-src 'self'already covers a same-origin file, so there's no inline-script hash to maintain.index.html+ one ~0.5 KB static file.Scoped deliberately to the jarring full-page flash. The minor button-label and disabled-state flashes are left out.
Test plan
npm run buildpasses (tsc --noEmit+ Vite);theme-init.jscopied todist/, path rewritten forbase: './'cv.theme=light, reload →data-theme="light"and light background on first paint'self')🤖 Generated with Claude Code