Skip to content
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(WebSocketClientManager): use localStorage for clients persistence #2127

Merged
merged 4 commits into from
Apr 12, 2024

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Apr 7, 2024

Changes

We have a bug that a new runtime doesn't really know about any other runtimes. It only keeps itself in the list of clients and notifies other runtimes about itself. That's not right.

BroadcastChannel is not a good API to introduce a shared state because one has to constantly keep that state in-sync. Instead, I propose we use localStorage to keep the serialized list of all the WebSocket clients for the app.

Roadmap

  • Rewrite src/core/ws/WebSocketClientManager.test.ts tests, the constructor signature and the behavior of WebSocketClientManager have changed.
  • Clear the localStorage key at some point.

@kettanaito kettanaito changed the title fix(ws): keep clients in localStorage fix(WebSocketClientManager): use localStorage for clients persistence Apr 7, 2024
@kettanaito kettanaito marked this pull request as ready for review April 12, 2024 18:50
if (typeof localStorage !== 'undefined') {
// When the worker clears the local storage key in "worker.stop()",
// also clear the in-memory clients map.
localStorage.removeItem = new Proxy(localStorage.removeItem, {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we would know when worker.stop() is called but the manager lives in ws.link() while the stop event is only ever available in handleWebSocketEvent().

This would be an insane context drilling. Instead, let's proxy the localStorage.removeItem() calls.

@kettanaito kettanaito merged commit ef0ebe3 into feat/ws Apr 12, 2024
12 checks passed
@kettanaito kettanaito deleted the fix/ws-manager-clients branch April 12, 2024 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant