Skip to content

Commit 87e5163

Browse files
committed
fix navigation race condition
1 parent c7e4101 commit 87e5163

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/components/Modal/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@ function Modal({fullscreen = true, onModalHide = () => {}, type, onModalShow = (
2121
};
2222

2323
const hideModal = () => {
24-
onModalHide();
2524
if ((window.history.state as WindowState)?.shouldGoBack && shouldHandleNavigationBack) {
25+
// Wait for history.back() to complete before calling onModalHide to prevent navigation race conditions
26+
const handleHistoryBack = () => {
27+
onModalHide();
28+
window.removeEventListener('popstate', handleHistoryBack);
29+
};
30+
window.addEventListener('popstate', handleHistoryBack, {once: true});
2631
window.history.back();
32+
} else {
33+
onModalHide();
2734
}
2835
};
2936

0 commit comments

Comments
 (0)