[Fix] Centralize theme ownership and sync meta[theme-color] on switch#192
Merged
[Fix] Centralize theme ownership and sync meta[theme-color] on switch#192
Conversation
Contributor
|
Hi @samzong, DetailsInstructions for interacting with me using comments are available here. |
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
Consolidate scattered theme state management (App.tsx local state + SettingsSheet DOM manipulation + duplicated constants) into a single
useThemeInithook that owns all theme side effects. Fixes stale<meta name="theme-color">that never updated on theme switch.Type of change
[Fix]bug fix[Refactor]internal cleanupWhy is this needed?
<meta name="theme-color">was hardcoded to#1c1c1c(wrong value —--bg-tertiary, not--bg-primary) and never updated when the user switched themes. On mobile PWA, the status bar stayed dark regardless of theme.useStatein App.tsx and Zustand store in SettingsSheet — completely disconnected.<Toaster>received stale theme.THEME_STORAGE_KEYwas independently declared in two files.data-theme,localStorage) was scattered across App.tsx and SettingsSheet with no single owner.What changed?
useThemeInithook — single owner for all theme side effects: appliesdata-theme,colorScheme, syncsmeta[theme-color]by reading--bg-primaryfrom computed CSS (no hardcoded color mapping), persists to localStorage, and listens for system preference changeslib/constants.ts— single definition ofTHEME_STORAGE_KEYstores/index.ts— synchronous theme hydration from localStorage at store creation (eliminates FOUC)App.tsx— removed ~30 lines of local theme state,resolveTheme(),applyTheme(), system preference listener; replaced withuseThemeInit()callSettingsSheet.tsx—toggleThemereduced tosetTheme(isDark ? 'light' : 'dark')— no DOM/localStorage manipulationindex.html— meta tag corrected from#1c1c1cto#000000Architecture impact
docs/architecture-invariants.md: noneLinked issues
N/A
Validation
pnpm lintpnpm testpnpm check:ui-contractpnpm check(full gate: lint + architecture + ui-contract + renderer-copy + i18n + dead-code + format + typecheck + test)Commands, screenshots, or notes:
Screenshots or recordings
No visual change. The meta tag update is only observable via DOM inspector or on mobile PWA status bar.
Release note
Checklist
[Fix]