From e89bd7796e2dcecaf0c483a795225ed9ec549bbd Mon Sep 17 00:00:00 2001 From: "mr. m" <91018726+mr-cheffy@users.noreply.github.com> Date: Sun, 30 Aug 2026 00:42:45 +0200 Subject: [PATCH] gh-15154: Fixed stale containers trying to sync across devices (gh-15166) --- src/zen/spaces/ZenSpaceManager.mjs | 17 +++++++++++ src/zen/sync/ZenSpacesSyncApplier.sys.mjs | 1 + src/zen/sync/ZenSpacesSyncModel.sys.mjs | 35 ++++++++++++++++------- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/zen/spaces/ZenSpaceManager.mjs b/src/zen/spaces/ZenSpaceManager.mjs index 6da584818..8439a1a67 100644 --- a/src/zen/spaces/ZenSpaceManager.mjs +++ b/src/zen/spaces/ZenSpaceManager.mjs @@ -156,11 +156,28 @@ class nsZenWorkspaces { this._invalidateBookmarkContainers(); }; Services.obs.addObserver(observerFunction, "workspace-bookmarks-updated"); + const onContainerDeleted = subject => { + const userContextId = subject?.wrappedJSObject?.userContextId; + for (const workspace of this.getWorkspaces()) { + if (workspace.containerTabId === userContextId) { + workspace.containerTabId = 0; + this.saveWorkspace(workspace); + } + } + }; + Services.obs.addObserver( + onContainerDeleted, + "contextual-identity-deleted" + ); window.addEventListener("unload", () => { Services.obs.removeObserver( observerFunction, "workspace-bookmarks-updated" ); + Services.obs.removeObserver( + onContainerDeleted, + "contextual-identity-deleted" + ); }); } } diff --git a/src/zen/sync/ZenSpacesSyncApplier.sys.mjs b/src/zen/sync/ZenSpacesSyncApplier.sys.mjs index c1068b25b..e166f5367 100644 --- a/src/zen/sync/ZenSpacesSyncApplier.sys.mjs +++ b/src/zen/sync/ZenSpacesSyncApplier.sys.mjs @@ -543,6 +543,7 @@ class nsZenSpacesSyncApplier { skipBackgroundNotify: true, lazyTabTitle: data.title || undefined, userContextId, + skipRoute: true, }); // Setting the sync id before the queued TabOpen handler runs makes // window sync treat this tab as already replicated. diff --git a/src/zen/sync/ZenSpacesSyncModel.sys.mjs b/src/zen/sync/ZenSpacesSyncModel.sys.mjs index 27167bfa9..1e59ff1b6 100644 --- a/src/zen/sync/ZenSpacesSyncModel.sys.mjs +++ b/src/zen/sync/ZenSpacesSyncModel.sys.mjs @@ -181,10 +181,18 @@ class nsZenSpacesSyncModel { if (!Number.isSafeInteger(id) || id <= 0) { return null; } + const data = this.#data(); + if (!lazy.ContextualIdentityService.getPublicIdentityFromId(id)) { + // A space or tab still pointing at a container that was deleted. + if (id in data.containers) { + delete data.containers[id]; + this.#file.saveSoon(); + } + return null; + } if (id <= BUILTIN_CONTAINER_MAX) { return `${BUILTIN_GUID_PREFIX}${id}`; } - const data = this.#data(); const existing = data.containers[id]; if (existing) { return existing; @@ -202,17 +210,27 @@ class nsZenSpacesSyncModel { if (typeof guid !== "string" || !guid) { return null; } + const data = this.#data(); + for (const [id, mapped] of Object.entries(data.containers)) { + if (mapped === guid) { + const contextId = Number(id); + if (lazy.ContextualIdentityService.getPublicIdentityFromId(contextId)) { + return contextId; + } + delete data.containers[id]; + this.#file.saveSoon(); + return null; + } + } if (guid.startsWith(BUILTIN_GUID_PREFIX)) { const id = Number(guid.slice(BUILTIN_GUID_PREFIX.length)); - return Number.isSafeInteger(id) && id > 0 && id <= BUILTIN_CONTAINER_MAX + return Number.isSafeInteger(id) && + id > 0 && + id <= BUILTIN_CONTAINER_MAX && + lazy.ContextualIdentityService.getPublicIdentityFromId(id) ? id : null; } - for (const [id, mapped] of Object.entries(this.#data().containers)) { - if (mapped === guid) { - return Number(id); - } - } return null; } @@ -223,9 +241,6 @@ class nsZenSpacesSyncModel { * @param {number} userContextId */ registerContainerGuid(guid, userContextId) { - if (guid.startsWith(BUILTIN_GUID_PREFIX)) { - return; - } this.#data().containers[userContextId] = guid; this.#file.saveSoon(); }