From b252004f48a39985c0715eb0bc1bf96085f97ce9 Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Mon, 2 Mar 2026 13:15:09 -0800 Subject: [PATCH] fix: disconnect from spaces and redirect on EncryptID sign-out Prevents stale WebSocket reconnect loops after sign-out by adding an intentional-disconnect flag to CommunitySync. Canvas and shell pages now redirect to homepage when the user signs out. Co-Authored-By: Claude Opus 4.6 --- lib/community-sync.ts | 7 +++++-- website/canvas.html | 8 ++++++++ website/shell.ts | 6 ++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/community-sync.ts b/lib/community-sync.ts index 89a5481..c7d1319 100644 --- a/lib/community-sync.ts +++ b/lib/community-sync.ts @@ -109,6 +109,7 @@ export class CommunitySync extends EventTarget { #doc: Automerge.Doc; #syncState: SyncState; #ws: WebSocket | null = null; + #disconnectedIntentionally = false; #communitySlug: string; #shapes: Map = new Map(); #pendingChanges: boolean = false; @@ -228,8 +229,9 @@ export class CommunitySync extends EventTarget { console.log(`[CommunitySync] Disconnected from ${this.#communitySlug}`); this.dispatchEvent(new CustomEvent("disconnected")); - // Attempt reconnect - this.#attemptReconnect(wsUrl); + if (!this.#disconnectedIntentionally) { + this.#attemptReconnect(wsUrl); + } }; this.#ws.onerror = (error) => { @@ -1134,6 +1136,7 @@ export class CommunitySync extends EventTarget { * Disconnect from server */ disconnect(): void { + this.#disconnectedIntentionally = true; if (this.#ws) { this.#ws.close(); this.#ws = null; diff --git a/website/canvas.html b/website/canvas.html index b95c353..22a5750 100644 --- a/website/canvas.html +++ b/website/canvas.html @@ -1346,6 +1346,13 @@ document.addEventListener("auth-change", () => { const sw = document.querySelector("rstack-space-switcher"); sw?.reload?.(); + + // If signed out, disconnect from space and go home + const session = localStorage.getItem("encryptid_session"); + if (!session) { + window.__communitySync?.disconnect?.(); + window.location.href = "/"; + } }); // Load module list for app switcher and tab bar + menu @@ -1677,6 +1684,7 @@ const offlineStore = new OfflineStore(); await offlineStore.open(); const sync = new CommunitySync(communitySlug, offlineStore); + window.__communitySync = sync; // Try to load from cache immediately (shows content before WebSocket connects) const hadCache = await sync.initFromCache(); diff --git a/website/shell.ts b/website/shell.ts index 0b0a7fd..b3b33a5 100644 --- a/website/shell.ts +++ b/website/shell.ts @@ -32,4 +32,10 @@ RStackMi.define(); document.addEventListener("auth-change", () => { const spaceSwitcher = document.querySelector("rstack-space-switcher") as any; spaceSwitcher?.reload?.(); + + // If signed out, redirect to homepage + const session = localStorage.getItem("encryptid_session"); + if (!session) { + window.location.href = "/"; + } });