From f6cda99b4ce06456745c1e3d5861cc594fcffdf4 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 26 Dec 2025 02:27:39 -0500 Subject: [PATCH] Fix back button closing modal --- src/components/Map/markerManager.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/Map/markerManager.js b/src/components/Map/markerManager.js index ff3f530..abb4f33 100644 --- a/src/components/Map/markerManager.js +++ b/src/components/Map/markerManager.js @@ -323,12 +323,13 @@ function normalizeImageUrl(raw) { return value; } -function closeCenteredOverlay(map) { +function closeCenteredOverlay(map, opts = {}) { try { const ov = map?.__swCenteredOverlay; if (!ov) return; if (ov.closing) return; ov.closing = true; + const skipHistory = !!opts.skipHistory; if (ov.onKey) window.removeEventListener("keydown", ov.onKey); if (ov.onAuth) window.removeEventListener("sociowire:auth-changed", ov.onAuth); @@ -352,7 +353,7 @@ function closeCenteredOverlay(map) { map.__swCenteredOverlay = null; - if (ov.historyPushed && !ov.historyClosed) { + if (!skipHistory && ov.historyPushed && !ov.historyClosed) { ov.historyClosed = true; try { window.history.back(); } catch {} } @@ -535,7 +536,10 @@ export function openCenteredOverlay({ map, post, theme, fullScreen = false }) { } onPop = () => { const ov = map.__swCenteredOverlay; - if (ov && ov.postId === postID) closeCenteredOverlay(map); + if (ov && ov.postId === postID) { + ov.historyClosed = true; + closeCenteredOverlay(map, { skipHistory: true }); + } }; window.addEventListener("popstate", onPop); } catch {}