diff --git a/frontend/src/lib/history.ts b/frontend/src/lib/history.ts index 46362c8..270fff2 100644 --- a/frontend/src/lib/history.ts +++ b/frontend/src/lib/history.ts @@ -66,9 +66,17 @@ export function useBackToClose(onClose: () => void): void { const idx = overlayStack.lastIndexOf(token); if (idx !== -1) { // 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); suppressPop = true; + const clearSuppress = () => { + suppressPop = false; + window.removeEventListener("popstate", clearSuppress); + }; + window.addEventListener("popstate", clearSuppress); window.history.back(); } };