mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
fix: settings popup reopen race after async open
Use DOM visibility and an open generation counter so in-flight opens cannot leave stale state after close, and dedupe opens per generation. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
242e4f3ff8
commit
5623c12904
5 files changed
+57
-38
No files matched your search
@@ -1,8 +1,5 @@
|
||||
import {
|
||||
changeSettingsClicked,
|
||||
closeExtensionPopup,
|
||||
SettingsClicked,
|
||||
} from "../Closers/closeExtensionPopup";
|
||||
import { closeExtensionPopup } from "../Closers/closeExtensionPopup";
|
||||
import { isExtensionSettingsOpen } from "../settingsPopupAnimation";
|
||||
|
||||
let isSettingsRendered = false;
|
||||
let settingsLoadPromise: Promise<void> | null = null;
|
||||
@@ -10,7 +7,7 @@ let resizerAttached = false;
|
||||
|
||||
function extensionOutsideClickHandler(extensionPopup: HTMLElement) {
|
||||
return (event: MouseEvent) => {
|
||||
if (!SettingsClicked) return;
|
||||
if (!isExtensionSettingsOpen()) return;
|
||||
|
||||
const target = event.target;
|
||||
if (!(target instanceof Node)) return;
|
||||
@@ -20,7 +17,7 @@ function extensionOutsideClickHandler(extensionPopup: HTMLElement) {
|
||||
if (target instanceof HTMLElement && target.closest("#AddedSettings")) return;
|
||||
if (target === extensionPopup) return;
|
||||
|
||||
changeSettingsClicked(closeExtensionPopup());
|
||||
closeExtensionPopup();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import { settingsPopup } from "@/seqta/utils/settingsPopup";
|
||||
import { animateSettingsClose } from "@/seqta/utils/settingsPopupAnimation";
|
||||
|
||||
export let SettingsClicked = false;
|
||||
let settingsOpenGeneration = 0;
|
||||
|
||||
export function getSettingsOpenGeneration(): number {
|
||||
return settingsOpenGeneration;
|
||||
}
|
||||
|
||||
export const closeExtensionPopup = (extensionPopup?: HTMLElement) => {
|
||||
settingsOpenGeneration += 1;
|
||||
|
||||
if (!extensionPopup) extensionPopup = document.getElementById("ExtensionPopup")!;
|
||||
|
||||
if (extensionPopup) {
|
||||
@@ -11,9 +17,4 @@ export const closeExtensionPopup = (extensionPopup?: HTMLElement) => {
|
||||
}
|
||||
|
||||
settingsPopup.triggerClose();
|
||||
return (SettingsClicked = false);
|
||||
};
|
||||
|
||||
export function changeSettingsClicked(newVal: boolean) {
|
||||
SettingsClicked = newVal;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import browser from "webextension-polyfill";
|
||||
import { getApiBase } from "@/seqta/utils/DevApiBase";
|
||||
import { SettingsClicked } from "@/seqta/utils/Closers/closeExtensionPopup";
|
||||
import { isExtensionSettingsOpen } from "@/seqta/utils/settingsPopupAnimation";
|
||||
import { isSeqtaEngageExperience } from "@/seqta/utils/isSeqtaEngage";
|
||||
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
|
||||
import {
|
||||
@@ -291,6 +291,6 @@ export function consumeOpenFeedbackRequest(): string | null {
|
||||
}
|
||||
|
||||
export function openExtensionSettingsPopup(): void {
|
||||
if (SettingsClicked) return;
|
||||
if (isExtensionSettingsOpen()) return;
|
||||
document.getElementById("AddedSettings")?.click();
|
||||
}
|
||||
@@ -1,9 +1,20 @@
|
||||
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
|
||||
|
||||
const HOST_OPEN_CLASS = "bsplus-settings-host--open";
|
||||
export const HOST_OPEN_CLASS = "bsplus-settings-host--open";
|
||||
const HOST_CLOSING_CLASS = "bsplus-settings-host--closing";
|
||||
const PANEL_OPEN_CLASS = "bsplus-settings-panel--open";
|
||||
|
||||
/** True when the settings host is shown (not fully hidden). */
|
||||
export function isSettingsHostVisiblyOpen(host: HTMLElement | null | undefined): boolean {
|
||||
if (!host) return false;
|
||||
if (host.classList.contains("hide")) return false;
|
||||
return host.classList.contains(HOST_OPEN_CLASS);
|
||||
}
|
||||
|
||||
export function isExtensionSettingsOpen(): boolean {
|
||||
return isSettingsHostVisiblyOpen(document.getElementById("ExtensionPopup"));
|
||||
}
|
||||
|
||||
function settingsPanel(host: HTMLElement): HTMLElement | null {
|
||||
return host.shadowRoot?.querySelector<HTMLElement>("[data-settings-panel]") ?? null;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
import {
|
||||
changeSettingsClicked,
|
||||
closeExtensionPopup,
|
||||
SettingsClicked,
|
||||
} from "./Closers/closeExtensionPopup";
|
||||
import {
|
||||
animateSettingsOpen,
|
||||
prefetchSettingsShell,
|
||||
} from "./settingsPopupAnimation";
|
||||
import { closeExtensionPopup, getSettingsOpenGeneration } from "./Closers/closeExtensionPopup";
|
||||
import { animateSettingsOpen, isExtensionSettingsOpen, prefetchSettingsShell } from "./settingsPopupAnimation";
|
||||
import { renderSettingsIfNeeded } from "./Adders/AddExtensionSettings";
|
||||
|
||||
export function setupSettingsButton() {
|
||||
@@ -18,8 +11,9 @@ export function setupSettingsButton() {
|
||||
|
||||
prefetchSettingsShell();
|
||||
|
||||
AddedSettings.addEventListener("click", async () => {
|
||||
if (SettingsClicked) {
|
||||
AddedSettings.addEventListener("click", async (event) => {
|
||||
event.stopPropagation();
|
||||
if (isExtensionSettingsOpen()) {
|
||||
closeExtensionPopup();
|
||||
} else {
|
||||
await openSettingsPopup();
|
||||
@@ -27,18 +21,34 @@ export function setupSettingsButton() {
|
||||
});
|
||||
}
|
||||
|
||||
let openSettingsInFlight: { gen: number; promise: Promise<void> } | null = null;
|
||||
|
||||
export async function openSettingsPopup(): Promise<void> {
|
||||
if (SettingsClicked && document.getElementById("ExtensionPopup")) return;
|
||||
if (isExtensionSettingsOpen()) return;
|
||||
|
||||
let extensionPopup = document.getElementById("ExtensionPopup");
|
||||
if (!extensionPopup) {
|
||||
const { addExtensionSettings } = await import("./Adders/AddExtensionSettings");
|
||||
addExtensionSettings();
|
||||
extensionPopup = document.getElementById("ExtensionPopup");
|
||||
}
|
||||
if (!extensionPopup) return;
|
||||
const gen = getSettingsOpenGeneration();
|
||||
if (openSettingsInFlight?.gen === gen) return openSettingsInFlight.promise;
|
||||
|
||||
await renderSettingsIfNeeded();
|
||||
animateSettingsOpen(extensionPopup);
|
||||
changeSettingsClicked(true);
|
||||
const promise = (async () => {
|
||||
try {
|
||||
let host = document.getElementById("ExtensionPopup");
|
||||
if (!host) {
|
||||
const { addExtensionSettings } = await import("./Adders/AddExtensionSettings");
|
||||
addExtensionSettings();
|
||||
host = document.getElementById("ExtensionPopup");
|
||||
}
|
||||
if (!host) return;
|
||||
|
||||
await renderSettingsIfNeeded();
|
||||
if (gen !== getSettingsOpenGeneration()) return;
|
||||
|
||||
host = document.getElementById("ExtensionPopup");
|
||||
if (host) animateSettingsOpen(host);
|
||||
} finally {
|
||||
if (openSettingsInFlight?.gen === gen) openSettingsInFlight = null;
|
||||
}
|
||||
})();
|
||||
|
||||
openSettingsInFlight = { gen, promise };
|
||||
return promise;
|
||||
}
|
||||
Reference in new issue
Block a user