-
Notifications
You must be signed in to change notification settings - Fork 5
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
fix: theme change sync issue #1616
Conversation
WalkthroughThe changes in this pull request focus on the Changes
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- packages/extension-polkagate/src/components/View.tsx (3 hunks)
- packages/extension-polkagate/src/components/chooseTheme.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/extension-polkagate/src/components/chooseTheme.ts
🔇 Additional comments (5)
packages/extension-polkagate/src/components/View.tsx (5)
4-8
: LGTM! Import organization improves type safety
The separation of type imports and explicit hook imports follows React best practices.
50-50
: LGTM! Efficient theme creation with proper memoization
The theme creation is correctly memoized based on mode changes.
65-65
: LGTM! Improved type safety for BodyTheme component
The explicit theme prop type improves type safety and code maintainability.
41-48
: 🛠️ Refactor suggestion
Consider optimizing toggleColorMode implementation
While the implementation is correct, consider batching the localStorage update and mode change to prevent potential multiple rerenders.
const colorMode = useMemo(() => ({
toggleColorMode: () => {
const toMode = mode === 'light' ? 'dark' : 'light';
-
- localStorage.setItem('theme', toMode);
- setMode(toMode);
+ Promise.resolve().then(() => {
+ localStorage.setItem('theme', toMode);
+ setMode(toMode);
+ });
}
}), [mode]);
Likely invalid or redundant comment.
23-39
: LGTM! Storage event handler implements proper theme synchronization
The implementation correctly handles theme synchronization across tabs with proper cleanup.
Let's verify the storage event handling:
✅ Verification successful
Theme synchronization implementation is correctly implemented and complete
The verification confirms that:
- Theme storage handling is properly centralized in
View.tsx
andchooseTheme.ts
- The storage event listener correctly syncs theme changes across tabs
- Theme persistence and retrieval logic is consistent:
chooseTheme.ts
handles initial theme detection and retrievalView.tsx
manages theme changes and cross-tab sync- Theme toggle properly persists changes to localStorage
- Proper cleanup of event listeners is implemented
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Verify that storage events are consistently handled across the codebase
rg -l "addEventListener.*storage" --type typescript
rg -l "localStorage.*theme" --type typescript
Length of output: 171
Script:
#!/bin/bash
# Let's try without typescript file type specification
rg -l "addEventListener.*storage"
rg -l "localStorage.*theme"
# Also search for theme-related storage operations
rg -l "setItem.*theme"
rg -l "getItem.*theme"
# Look for any theme mode related code
rg -A 3 "PaletteMode"
Length of output: 1409
Script:
#!/bin/bash
# Let's examine the theme handling implementation in chooseTheme.ts
cat packages/extension-polkagate/src/components/chooseTheme.ts
# And check the complete View.tsx for theme-related logic
cat packages/extension-polkagate/src/components/View.tsx
Length of output: 2788
## [0.21.1](v0.21.0...v0.21.1) (2024-10-29) ### Bug Fixes * theme change sync issue ([#1616](#1616)) ([69bccb0](69bccb0))
Close: #1615
Summary by CodeRabbit
New Features
View
component to respond to local storage changes for theme settings, allowing for dynamic theme updates.View
component.Bug Fixes
Documentation