-
Notifications
You must be signed in to change notification settings - Fork 36
fix: improved theme logic #504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
|
Claude finished @ignaciosantise's task —— View job PR Review: Theme Logic ImprovementsSummaryThis PR improves the theme management architecture by introducing a derived state pattern using Issues Found1. Type Safety Issue in
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the theme management logic to introduce a clearer separation between system theme and user-defined default theme using valtio's derived state pattern.
Key Changes:
- Introduced
derive-valtioto create a computedthemeModethat prioritizesdefaultThemeModeoversystemThemeMode - Renamed
setThemeModetosetDefaultThemeModefor the user-facing API and addedsetSystemThemeModefor tracking system theme changes - Updated the modal to always track system theme changes via
setSystemThemeMode, while the hook API usessetDefaultThemeModeto respect user preferences
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/core/src/controllers/ThemeController.ts | Refactored to use derived state pattern with separate system and default theme modes |
| packages/appkit/src/modal/w3m-modal/index.tsx | Updated to use setSystemThemeMode for tracking system theme changes |
| packages/appkit/src/hooks/useAppKitTheme.ts | Changed setThemeMode to call setDefaultThemeMode internally |
| packages/appkit/src/tests/hooks/useAppKitTheme.test.tsx | Updated test expectations to reflect new default behavior and API changes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| systemThemeMode?: ThemeMode | null; | ||
| defaultThemeMode?: ThemeMode | null; |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type inconsistency: systemThemeMode and defaultThemeMode are typed as ThemeMode | null but are initialized with undefined. This creates a mismatch between the type definition and the actual runtime values. Consider either:
- Changing the type to
ThemeMode | null | undefinedorThemeMode | undefined - Initializing with
nullinstead ofundefinedon lines 14-15
This inconsistency could lead to type-safety issues when accessing these properties.
| state.themeMode = themeMode; | ||
| } | ||
| setSystemThemeMode(systemThemeMode?: ThemeControllerState['systemThemeMode']) { | ||
| baseState.systemThemeMode = systemThemeMode ?? 'light'; |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setSystemThemeMode function always defaults to 'light' when the parameter is undefined or null. However, when the system theme changes to null (which useColorScheme() can return), this will force it to 'light' rather than preserving the null value. This could prevent proper fallback to the default theme mode. Consider allowing null to be set when explicitly passed, or handle the React Native's useColorScheme() null return value more gracefully.
| baseState.systemThemeMode = systemThemeMode ?? 'light'; | |
| baseState.systemThemeMode = systemThemeMode === undefined ? 'light' : systemThemeMode; |
|



Summary
Improved theme and setTheme logic
Note
Refactors theme logic to derive
themeModefromsystemThemeModeanddefaultThemeMode, replacingsetThemeMode, and updates hook, modal, and tests accordingly.ThemeController):baseStatewithsystemThemeMode,defaultThemeMode, andthemeVariablesand derivesthemeModeviaderive-valtio.setThemeModewithsetSystemThemeModeandsetDefaultThemeMode; removes reliance onAppearance.subscribeto use derived state; adjusts state mutations tobaseState.themeMode, precedence, and new setters.useAppKitTheme:themeModenow required; usesThemeController.setDefaultThemeModeand exposes stable setters.w3m-modal): syncs system theme viaThemeController.setSystemThemeMode(theme ?? undefined); removesdefaultThemeModeusage in snapshot.lightbehavior.Written by Cursor Bugbot for commit a7f1584. This will update automatically on new commits. Configure here.