diff --git a/app/soapbox/components/modal-root.tsx b/app/soapbox/components/modal-root.tsx index f3cdac7da..a51b54a12 100644 --- a/app/soapbox/components/modal-root.tsx +++ b/app/soapbox/components/modal-root.tsx @@ -105,8 +105,10 @@ const ModalRoot: React.FC = ({ children, onCancel, onClose, type }) const handleModalOpen = () => { modalHistoryKey.current = Date.now(); - unlistenHistory.current = history.listen((_, action) => { - if (action === 'POP') { + unlistenHistory.current = history.listen(({ state }, action) => { + if (!(state as any)?.soapboxModalKey) { + onClose(); + } else if (action === 'POP') { handleOnClose(); if (onCancel) onCancel(); @@ -118,11 +120,9 @@ const ModalRoot: React.FC = ({ children, onCancel, onClose, type }) if (unlistenHistory.current) { unlistenHistory.current(); } - if (!['FAVOURITES', 'MENTIONS', 'REACTIONS', 'REBLOGS', 'MEDIA'].includes(type)) { - const { state } = history.location; - if (state && (state as any).soapboxModalKey === modalHistoryKey.current) { - history.goBack(); - } + const { state } = history.location; + if (state && (state as any).soapboxModalKey === modalHistoryKey.current) { + history.goBack(); } }; @@ -174,7 +174,7 @@ const ModalRoot: React.FC = ({ children, onCancel, onClose, type }) ensureHistoryBuffer(); } - }); + }, [children]); if (!visible) { return (