Repository navigation
fix(theme): keep stored preference across hard refresh - #951
Merged
Nanafancy merged 1 commit intoOct 21, 2026
Merged
Conversation
|
@moon-code12 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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
Pins the hard-refresh theme behavior and removes the last way the stored preference can drift.
THEME_STORAGE_KEY/CONTRAST_STORAGE_KEYas the single source of truth.getStoredTheme,storeTheme,getStoredContrast,storeContrast, and the blockingthemeBootstrapScriptnow all use those constants instead of repeating string literals.tests/theme-hard-refresh.test.tsx, which runs the real<head>bootstrap script, drops the module store to simulate a full reload, then mountsThemeToggle:light+ OS dark -> stays light,dark+ OS light -> stays dark,system-> follows the OS,This also documents and protects the earlier #627 fix (blocking first-paint script + one shared store), which is what prevents the OS scheme from overwriting an explicit choice after refresh.
Closes #865
Closes #843
Root cause / behavior
The toggle writes an explicit mode to
localStorage; the blocking script and the React store must read the same key before the first paint. A key mismatch (or a missing pre-paint read) leaves the page on the system scheme until hydration, and anysystemconsumer can then re-apply it. The bootstrap script and the store now share exported constants, and the regression test runs the actual bootstrap script rather than a reimplementation.No user-facing behavior is intended to change: the key names are still
themeandcontrast; only their definition is centralized.Tests
cd ignition-pay-frontend npx vitest run tests/theme-hard-refresh.test.tsx tests/theme-persistence.test.tsx tests/use-theme.test.tsxBreakdown:
theme-hard-refresh.test.tsx: 4 new teststheme-persistence.test.tsx: 18 passeduse-theme.test.tsx: 12 passedLint:
Passed with no errors/warnings.
Type-check:
npx tsc --noEmitproduced no errors for the changed files.