From 79efc532c79530df1a31baa847aaedbd1ef62adc Mon Sep 17 00:00:00 2001 From: Jesse Andrews Date: Thu, 13 Feb 2025 15:39:12 -0500 Subject: [PATCH 1/2] Default to last visited replica --- .../jumble/src/contexts/CharmManagerContext.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/typescript/packages/jumble/src/contexts/CharmManagerContext.tsx b/typescript/packages/jumble/src/contexts/CharmManagerContext.tsx index f78fd1c15..9f759f3fd 100644 --- a/typescript/packages/jumble/src/contexts/CharmManagerContext.tsx +++ b/typescript/packages/jumble/src/contexts/CharmManagerContext.tsx @@ -12,7 +12,17 @@ const CharmManagerContext = createContext(null!); export const CharmsManagerProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { const { replicaName } = useParams<{ replicaName: string }>(); - const effectiveReplica = replicaName || "common-knowledge"; + + let effectiveReplica: string; + if (replicaName) { + // When a replica is provided in the URL, use it and save it as the last visited + effectiveReplica = replicaName; + localStorage.setItem("lastReplica", replicaName); + } else { + // Otherwise, pull the last visited replica from local storage. + // Falling back to "common-knowledge" if nothing was stored. + effectiveReplica = localStorage.getItem("lastReplica") || "common-knowledge"; + } // NOTE(ja): disable switching replicas until // https://github.com/commontoolsinc/labs/issues/377 is fixed From 75ae6952d0d01e28fda26dd9a2c8bcc7a4c7ccec Mon Sep 17 00:00:00 2001 From: Jesse Andrews Date: Thu, 13 Feb 2025 15:48:19 -0500 Subject: [PATCH 2/2] fix(subscription): gracefully handle in-flight updates for cancelled subscriptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, integrate() would throw an error ("Subscription is cancelled") if an update arrived after the subscription had been cancelled. This happened due to a race condition where in-flight updates were still delivered even after the subscription was removed from active subscriber lists. Now, integrate() checks if the subscription’s controller is missing and logs a warning while ignoring the update, rather than throwing an error. This ensures that cancelled subscriptions do not cause fatal errors while preventing memory leaks by properly unwatching and clearing subscriber channels. fixes #378 --- typescript/packages/common-memory/subscription.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/packages/common-memory/subscription.ts b/typescript/packages/common-memory/subscription.ts index 8991fc3ed..a4b1deb73 100644 --- a/typescript/packages/common-memory/subscription.ts +++ b/typescript/packages/common-memory/subscription.ts @@ -78,7 +78,7 @@ export const integrate = (session: Session, change: In) => { if (session.controller) { session.controller.enqueue(change); } else { - throw new Error("Subscription is cancelled"); + console.warn("Subscription is cancelled, not integrating change", change); } };