about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2024-12-17 03:13:51 +0000
committerGitHub <noreply@github.com>2024-12-17 03:13:51 +0000
commit20d4266e2f8ef82b6ed1244fd929dd07c01486dc (patch)
treec6f057cc31d566263926a955a99eb8125af7cdc5 /src
parentc9e429760d426df7549bfcd6292a0dc5e7fe7d7e (diff)
downloadvoidsky-20d4266e2f8ef82b6ed1244fd929dd07c01486dc.tar.zst
Read storage on window.onstorage (#7137)
Diffstat (limited to 'src')
-rw-r--r--src/state/persisted/index.web.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/state/persisted/index.web.ts b/src/state/persisted/index.web.ts
index 4cfc87cdb..f28b19771 100644
--- a/src/state/persisted/index.web.ts
+++ b/src/state/persisted/index.web.ts
@@ -24,6 +24,7 @@ const _emitter = new EventEmitter()
 
 export async function init() {
   broadcast.onmessage = onBroadcastMessage
+  window.onstorage = onStorage
   const stored = readFromStorage()
   if (stored) {
     _state = stored
@@ -90,6 +91,17 @@ export async function clearStorage() {
 }
 clearStorage satisfies PersistedApi['clearStorage']
 
+function onStorage() {
+  const next = readFromStorage()
+  if (next === _state) {
+    return
+  }
+  if (next) {
+    _state = next
+    _emitter.emit('update')
+  }
+}
+
 async function onBroadcastMessage({data}: MessageEvent) {
   if (
     typeof data === 'object' &&