diff --git a/src/hooks/useDiscardChangesConfirmation/index.ts b/src/hooks/useDiscardChangesConfirmation/index.ts index f06f06e3e7b5..e0a2647ca9fe 100644 --- a/src/hooks/useDiscardChangesConfirmation/index.ts +++ b/src/hooks/useDiscardChangesConfirmation/index.ts @@ -2,7 +2,6 @@ import type {NavigationAction} from '@react-navigation/native'; import {useFocusEffect, useIsFocused} from '@react-navigation/native'; import {useEffect, useRef} from 'react'; import {ModalActions} from '@components/Modal/Global/ModalContext'; -import {isInternalPopstateInProgress} from '@components/Modal/internalPopstateGuard'; import useBeforeRemove from '@hooks/useBeforeRemove'; import useConfirmModal from '@hooks/useConfirmModal'; import useLocalize from '@hooks/useLocalize'; @@ -120,11 +119,8 @@ function useDiscardChangesConfirmation({getHasUnsavedChanges, onCancel, onVisibi * already moved — this listener restores it with `history.go(1)`, and dismisses the prompt as Cancel when the back happened over it. */ useEffect(() => { - // Register exactly once: re-registering on render would move this listener behind `withInternalPopstate`'s one-shot flag reset, breaking the internal-popstate detection + // Register exactly once so the listener keeps its original browser event ordering. const handlePopState = () => { - if (isInternalPopstateInProgress()) { - return; - } if (isRestoringHistory.current) { isRestoringHistory.current = false; return; diff --git a/tests/unit/hooks/useDiscardChangesConfirmation.test.ts b/tests/unit/hooks/useDiscardChangesConfirmation.test.ts index 2367b9b58a40..a54da8f713ba 100644 --- a/tests/unit/hooks/useDiscardChangesConfirmation.test.ts +++ b/tests/unit/hooks/useDiscardChangesConfirmation.test.ts @@ -1,5 +1,4 @@ import {act, renderHook} from '@testing-library/react-native'; -import {withInternalPopstate} from '@components/Modal/internalPopstateGuard'; import type {DiscardChangesConfirmation} from '@hooks/useDiscardChangesConfirmation/types'; import type UseDiscardChangesConfirmationOptions from '@hooks/useDiscardChangesConfirmation/types'; @@ -304,25 +303,5 @@ describe('useDiscardChangesConfirmation (web)', () => { expect(historyGoSpy).not.toHaveBeenCalled(); expect(mockShowConfirmModal).not.toHaveBeenCalled(); }); - - it('ignores internal popstate events from modal history cleanup', () => { - renderDiscardHook(() => true); - - invokeBeforeRemove('RESET'); - - act(() => { - withInternalPopstate(() => { - window.dispatchEvent(new PopStateEvent('popstate')); - }); - }); - - // The internal popstate must not consume the pending URL restore - expect(historyGoSpy).not.toHaveBeenCalled(); - - dispatchPopstate(); - - expect(historyGoSpy).toHaveBeenCalledTimes(1); - expect(historyGoSpy).toHaveBeenCalledWith(1); - }); }); });