From cd6d979b5a88d2a69798c0eabe14d2a19e9d546a Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Tue, 24 Mar 2026 16:14:12 -0700 Subject: [PATCH] feat(shell): connect CommunitySync for cross-browser tab sync on all pages Tab list sync via Automerge previously only worked on canvas pages. Init CommunitySync + OfflineStore in the shell entry point so community-sync-ready fires on every non-demo shell page, enabling real-time tab sync across all browsers via the existing inline handler. Co-Authored-By: Claude Opus 4.6 --- website/shell.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/website/shell.ts b/website/shell.ts index c6b35b0..8043899 100644 --- a/website/shell.ts +++ b/website/shell.ts @@ -24,6 +24,8 @@ import { RStackUserDashboard } from "../shared/components/rstack-user-dashboard" import { rspaceNavUrl } from "../shared/url-helpers"; import { TabCache } from "../shared/tab-cache"; import { RSpaceOfflineRuntime } from "../shared/local-first/runtime"; +import { CommunitySync } from "../lib/community-sync"; +import { OfflineStore } from "../lib/offline-store"; // Expose URL helper globally (used by shell inline scripts + components) (window as any).__rspaceNavUrl = rspaceNavUrl; @@ -77,6 +79,31 @@ if (spaceSlug && spaceSlug !== "demo") { window.addEventListener("beforeunload", () => { runtime.flush(); }); + + // ── CommunitySync (tab list Automerge sync) ── + const offlineStore = new OfflineStore(); + const communitySync = new CommunitySync(spaceSlug, offlineStore); + (window as any).__communitySync = communitySync; + + (async () => { + try { + await offlineStore.open(); + await communitySync.initFromCache(); + } catch (e) { + console.warn("[shell] CommunitySync cache init failed:", e); + } + document.dispatchEvent(new CustomEvent("community-sync-ready", { + detail: { sync: communitySync, communitySlug: spaceSlug }, + })); + + const proto = location.protocol === "https:" ? "wss:" : "ws:"; + const wsUrl = `${proto}//${location.host}/ws/${spaceSlug}`; + communitySync.connect(wsUrl); + })(); + + window.addEventListener("beforeunload", () => { + communitySync.saveBeforeUnload(); + }); } // ── Track space visits for dashboard recency sorting ──