Simplify theme caching logic#13593
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ PR preview is ready!
|
📈 Frontend coverage change detectedThe frontend unit test (vitest) coverage has increased by 0.0800%
🎉 Great job on improving test coverage! |
6a46d70 to
b55bac3
Compare
There was a problem hiding this comment.
Pull request overview
This pull request simplifies theme caching logic by storing only high-level theme selection strings ("System", "Light", "Dark") in localStorage instead of persisting complete theme configurations. The refactor improves handling of system preference updates for custom themes and ensures embed options consistently take precedence over cached theme preferences.
Changes:
- Simplified cache format from storing full ThemeConfig objects to storing simple ThemeSelection strings
- Added
getPreferredThemeutility to unify preference retrieval logic - Enhanced system preference change handling for both preset and custom auto themes
- Incremented cache version to 2 and added migration logic to clear old cache formats
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/lib/src/util/storageUtils.ts | Incremented CACHED_THEME_VERSION to 2 |
| frontend/lib/src/theme/utils.ts | Replaced getCachedTheme/setCachedTheme with getCachedThemeSelection/setCachedThemeSelection; added getPreferredTheme and getThemeSelectionFromThemeConfig utilities; simplified mapping logic |
| frontend/lib/src/theme/utils.test.ts | Updated tests to work with new string-based cache format |
| frontend/lib/src/theme/types.ts | Redefined CachedTheme as ThemeSelection alias instead of object type |
| frontend/lib/src/index.ts | Updated exports to reflect renamed and new functions |
| frontend/app/src/util/useThemeManager.ts | Enhanced auto theme recalibration logic for custom themes; split updateTheme into applyTheme and updateTheme for better control over persistence |
| frontend/app/src/util/useThemeManager.test.ts | Added comprehensive tests for system preference changes with custom themes |
| frontend/app/src/App.tsx | Simplified theme preference logic by using new getPreferredTheme utility |
| frontend/app/src/App.test.tsx | Updated test expectations to match new string-based cache format |
| e2e_playwright/main_menu_test.py | Added E2E tests for cached preference persistence and auto theme recalibration |
| e2e_playwright/main_menu.py | Added header to test app |
SummaryThis PR refactors the theme caching logic to store only a high-level selection (
Code QualityStrengths:
Implementation Details:
Minor Observations:
Test CoverageUnit Tests:
E2E Tests:
Test Quality Assessment:
Backwards CompatibilityBreaking Changes:
Migration Handling:
API Changes:
Security & RiskSecurity:
Risk Assessment:
RecommendationsNo blocking issues identified. The following are minor suggestions for consideration:
VerdictAPPROVED: This is a well-implemented refactoring that simplifies theme caching logic while maintaining backwards compatibility. The code is clean, well-tested at both unit and E2E levels, and follows established patterns in the codebase. The schema version bump ensures a clean migration path for existing users. This is an automated AI review. Please verify the feedback and use your judgment. |
Describe your changes
Refactor theme caching logic to store only the high‑level selection -
"System","Light", or"Dark"in localStorage as a simple string instead of persisting any theme configs.We previously did not save
"Auto"but since we are not saving config properties anymore, it is easier to save "Auto" as long as we ensure this is recalculated properly for system setting changes.Testing Plan