Skip to content

Commit fba0c33

Browse files
authored
Revert "Fix double modal hide callbacks when unmounted"
1 parent 359c8c2 commit fba0c33

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/components/Modal/BaseModal.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ function BaseModal(
109109
const insets = useSafeAreaInsets();
110110

111111
const isVisibleRef = useRef(isVisible);
112+
const hideModalCallbackRef = useRef<(callHideCallback: boolean) => void>(undefined);
113+
112114
const wasVisible = usePrevious(isVisible);
113115

114116
const uniqueModalId = useMemo(() => modalId ?? ComposerFocusManager.getId(), [modalId]);
@@ -158,6 +160,22 @@ function BaseModal(
158160
};
159161
}, [isVisible, wasVisible, onClose, type]);
160162

163+
useEffect(() => {
164+
hideModalCallbackRef.current = hideModal;
165+
}, [hideModal]);
166+
167+
useEffect(
168+
() => () => {
169+
// Only trigger onClose and setModalVisibility if the modal is unmounting while visible.
170+
if (!isVisibleRef.current) {
171+
return;
172+
}
173+
hideModalCallbackRef.current?.(true);
174+
},
175+
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
176+
[],
177+
);
178+
161179
const handleShowModal = useCallback(() => {
162180
if (shouldSetModalVisibility) {
163181
setModalVisibility(true, type);

0 commit comments

Comments
 (0)