gh-15154: Fixed stale containers trying to sync across devices (gh-15166)

This commit is contained in:
mr. m 2026-08-30 00:42:45 +02:00 committed by GitHub
parent 66c5931a29
commit e89bd7796e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 43 additions and 10 deletions

View File

@ -156,11 +156,28 @@ class nsZenWorkspaces {
this._invalidateBookmarkContainers(); this._invalidateBookmarkContainers();
}; };
Services.obs.addObserver(observerFunction, "workspace-bookmarks-updated"); 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", () => { window.addEventListener("unload", () => {
Services.obs.removeObserver( Services.obs.removeObserver(
observerFunction, observerFunction,
"workspace-bookmarks-updated" "workspace-bookmarks-updated"
); );
Services.obs.removeObserver(
onContainerDeleted,
"contextual-identity-deleted"
);
}); });
} }
} }

View File

@ -543,6 +543,7 @@ class nsZenSpacesSyncApplier {
skipBackgroundNotify: true, skipBackgroundNotify: true,
lazyTabTitle: data.title || undefined, lazyTabTitle: data.title || undefined,
userContextId, userContextId,
skipRoute: true,
}); });
// Setting the sync id before the queued TabOpen handler runs makes // Setting the sync id before the queued TabOpen handler runs makes
// window sync treat this tab as already replicated. // window sync treat this tab as already replicated.

View File

@ -181,10 +181,18 @@ class nsZenSpacesSyncModel {
if (!Number.isSafeInteger(id) || id <= 0) { if (!Number.isSafeInteger(id) || id <= 0) {
return null; 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) { if (id <= BUILTIN_CONTAINER_MAX) {
return `${BUILTIN_GUID_PREFIX}${id}`; return `${BUILTIN_GUID_PREFIX}${id}`;
} }
const data = this.#data();
const existing = data.containers[id]; const existing = data.containers[id];
if (existing) { if (existing) {
return existing; return existing;
@ -202,17 +210,27 @@ class nsZenSpacesSyncModel {
if (typeof guid !== "string" || !guid) { if (typeof guid !== "string" || !guid) {
return null; 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)) { if (guid.startsWith(BUILTIN_GUID_PREFIX)) {
const id = Number(guid.slice(BUILTIN_GUID_PREFIX.length)); 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 ? id
: null; : null;
} }
for (const [id, mapped] of Object.entries(this.#data().containers)) {
if (mapped === guid) {
return Number(id);
}
}
return null; return null;
} }
@ -223,9 +241,6 @@ class nsZenSpacesSyncModel {
* @param {number} userContextId * @param {number} userContextId
*/ */
registerContainerGuid(guid, userContextId) { registerContainerGuid(guid, userContextId) {
if (guid.startsWith(BUILTIN_GUID_PREFIX)) {
return;
}
this.#data().containers[userContextId] = guid; this.#data().containers[userContextId] = guid;
this.#file.saveSoon(); this.#file.saveSoon();
} }