Merge: fix back button swallowed after a button/ESC overlay close

This commit is contained in:
npeter83 2026-07-01 01:42:00 +02:00
commit 703ae41f2d

View file

@ -66,9 +66,17 @@ export function useBackToClose(onClose: () => void): void {
const idx = overlayStack.lastIndexOf(token); const idx = overlayStack.lastIndexOf(token);
if (idx !== -1) { if (idx !== -1) {
// Closed programmatically (not via Back): drop our own history entry, and tell the // Closed programmatically (not via Back): drop our own history entry, and tell the
// remaining overlays' handlers to ignore the resulting popstate. // remaining overlays' handlers to ignore the resulting popstate. A one-shot listener
// clears the flag on that very popstate even when NO overlay remains underneath to
// consume it — otherwise suppressPop leaks `true` and silently swallows the NEXT
// overlay's first Back (reopen-after-button-close → first Back does nothing).
overlayStack.splice(idx, 1); overlayStack.splice(idx, 1);
suppressPop = true; suppressPop = true;
const clearSuppress = () => {
suppressPop = false;
window.removeEventListener("popstate", clearSuppress);
};
window.addEventListener("popstate", clearSuppress);
window.history.back(); window.history.back();
} }
}; };