-
Notifications
You must be signed in to change notification settings - Fork 3
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
Broadcast cache writes to all tabs/windows #1606
base: develop
Are you sure you want to change the base?
Conversation
This allows fresh data from one tab to be applied to all tabs. Each tab still has its own cache, changes are just synced. So refreshing the page will still initialize empty, so if some data point became stale (now in all tabs), the user can refresh one page, and the fresh data will refresh all tabs.
89d7f21
to
ebd038c
Compare
📝 WalkthroughWalkthroughThe changes introduce functionality for inter-window communication in the application using the Changes
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
🧹 Outside diff range and nitpick comments (1)
src/api/client/createCache.ts (1)
32-36
: Consider using more descriptive variable and function namesFor improved code readability, consider renaming variables:
- Rename
orig
tooriginalWrite
to clearly indicate its purpose.- Rename
ourWrite
tobroadcastedWrite
orwrappedWrite
to reflect its role in broadcasting and overriding the cache's write method.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- src/api/client/ImpersonationContext.tsx (4 hunks)
- src/api/client/createCache.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (5)
src/api/client/createCache.ts (2)
2-2
: LGTMThe import statement correctly brings in the
Cache
type for use in type annotations.
30-39
: EnsureCache.WriteOptions
is serializable before broadcastingThe
options
object passed towriteChannel.postMessage(options);
in line 34 must be serializable using the structured clone algorithm used byBroadcastChannel
. Verify thatCache.WriteOptions
does not contain any functions or non-serializable data types to prevent runtime errors when broadcasting cache writes.src/api/client/ImpersonationContext.tsx (3)
31-35
: Initialization of BroadcastChannel is correctThe use of
useState
to conditionally initialize thebroadcast
channel ensures compatibility with environments whereBroadcastChannel
is not available.
49-49
: Broadcasting impersonation state changesThe line
broadcast?.postMessage(next);
effectively broadcasts state changes to other tabs whenBroadcastChannel
is available.
59-59
: Includingbroadcast
in the dependency array ofset
Including
broadcast
in the dependency array of theset
function'suseCallback
ensures that any changes tobroadcast
will update theset
function, which is appropriate.
This allows fresh data from one tab to be applied to all tabs.
Each tab still has its own cache, changes are just synced.
So refreshing the page will still initialize empty, so if some data point became stale (now in all tabs), the user can refresh one page, and the fresh data will refresh all tabs.
Summary by CodeRabbit
New Features
BroadcastChannel
API.Bug Fixes