fix: Fixed race conditions when syncing views through windows desktops, b=bug #12390, c=no-component

This commit is contained in:
mr. m
2026-02-25 20:31:28 +01:00
parent 2c740b1abf
commit 5e27368a48

View File

@@ -1259,11 +1259,10 @@ class nsZenWindowSync {
});
}
async on_focus(aEvent) {
on_focus(aEvent) {
if (typeof aEvent.target !== "object") {
return;
}
await this.#docShellSwitchPromise;
const window = Services.focus.activeWindow;
if (
!window?.gBrowser ||
@@ -1273,23 +1272,31 @@ class nsZenWindowSync {
) {
return;
}
let promise = this.#docShellSwitchPromise;
this.#lastFocusedWindow = new WeakRef(window);
this.#lastSelectedTab = new WeakRef(window.gBrowser.selectedTab);
return (this.#docShellSwitchPromise = this.#onTabSwitchOrWindowFocus(window));
// eslint-disable-next-line no-async-promise-executor
this.#docShellSwitchPromise = new Promise(async (resolve) => {
await promise;
await this.#onTabSwitchOrWindowFocus(window);
resolve();
});
}
async on_TabSelect(aEvent) {
await this.#docShellSwitchPromise;
on_TabSelect(aEvent) {
const tab = aEvent.target;
if (this.#lastSelectedTab?.deref() === tab) {
return;
}
this.#lastSelectedTab = new WeakRef(tab);
const previousTab = aEvent.detail.previousTab;
return (this.#docShellSwitchPromise = this.#onTabSwitchOrWindowFocus(
aEvent.target.ownerGlobal,
previousTab
));
let promise = this.#docShellSwitchPromise;
// eslint-disable-next-line no-async-promise-executor
this.#docShellSwitchPromise = new Promise(async (resolve) => {
await promise;
await this.#onTabSwitchOrWindowFocus(tab.ownerGlobal, previousTab);
resolve();
});
}
on_SSWindowClosing(aEvent) {