fix(ui): persist theme selection across page reloads - #33
Open
CatJuly wants to merge 1 commit into
Open
Conversation
The theme picker kept its value in plain React state, so every page refresh reset the UI to the default `openopc` theme and the user had to re-select their preference each time. Locale, sidebar collapse, and the outdoor-lighting override already survive reloads through localStorage; the theme was the one preference that never did. Initialize the theme state lazily from `opc_office_theme` (validated against the known theme names so a stale or tampered value falls back to the default) and write the key on every change, wrapped in try/catch like the neighbouring preferences so private browsing modes degrade gracefully. Verified with `npm run typecheck` and `npm run build`; manually switched to the paper theme, hard-refreshed, and the paper theme was restored; an invalid stored value falls back to the default.
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
The theme selected in the top-bar picker does not survive a page reload — every refresh resets the UI to the default
openopctheme, forcing users to re-select their preference each time.Repro: switch to any non-default theme (e.g. Paper) → press F5 → the UI is back to the default theme.
Root cause
App.tsxkeeps the theme in plain React state with a hardcoded initial value:Nothing ever writes the choice anywhere, so each page load re-initializes from the literal. Notably the neighbouring preferences — locale (
openopc_locale), sidebar collapse (opc_office_sidebar_collapsed), and the outdoor-lighting override (opc_outdoor_override) — all already persist through localStorage; the theme was the one preference that never did.Fix
Follow the file's own persistence conventions:
opc_office_theme, validating the stored value against the known theme names so a stale or tampered entry falls back to the default instead of producing a broken class name.Testing
npm run typecheck— cleannpm run build— clean; rebuiltfrontend_distbundle includedopc_office_themeand confirmed fallback to the defaultScope
Frontend only (
App.tsx+ rebuilt dist). Independent of my other open PRs — no shared files.