diff --git a/src/pages/TransactionDuplicate/Confirmation.tsx b/src/pages/TransactionDuplicate/Confirmation.tsx index 28456f38eca8..8585c2ed6c8f 100644 --- a/src/pages/TransactionDuplicate/Confirmation.tsx +++ b/src/pages/TransactionDuplicate/Confirmation.tsx @@ -23,6 +23,7 @@ import useTransactionThreadReportIDs from '@hooks/useTransactionThreadReportIDs' import {mergeDuplicates, resolveDuplicates} from '@libs/actions/IOU/Duplicate'; import {setDeleteTransactionNavigateBackUrl} from '@libs/actions/Report'; import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; +import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import type {TransactionDuplicateNavigatorParamList} from '@libs/Navigation/types'; @@ -104,9 +105,7 @@ function Confirmation() { const handleMergeDuplicates = useCallback(() => { const transactionThreadReportID = childReportID ?? generateReportID(); const mergeParams = !childReportID ? {...transactionsMergeParams, transactionThreadReportID} : transactionsMergeParams; - // Server deletes the discarded transaction's now-empty expense report on merge and - // pushes back a "Report not found" payload for it. Hint the guard and redirect to - // the kept transaction's report so the user doesn't land on the discarded one. + // Suppress the NotFound guard for the discarded thread the server tears down on merge. const keptReportRoute = ROUTES.REPORT_WITH_ID.getRoute(mergeParams.reportID); setDeleteTransactionNavigateBackUrl(keptReportRoute); mergeDuplicates({...mergeParams, ...taxData, currentUserAccountID, currentUserLogin: currentUserLogin ?? ''}); @@ -114,12 +113,15 @@ function Confirmation() { Navigation.dismissToSuperWideRHP(); return; } - const topmostReportID = Navigation.getTopmostReportId?.(); - if (topmostReportID === mergeParams.reportID) { + // From Search, dismiss back to the results (backTo is always set here, so it can't detect Search). + if (isSearchTopmostFullScreenRoute()) { Navigation.dismissModal(); - } else { - Navigation.goBack(keptReportRoute); + return; } + // From the discarded thread: pop the modal entries, then replace the dead thread with the kept report. + Navigation.dismissModal({ + afterTransition: () => Navigation.navigate(keptReportRoute, {forceReplace: true}), + }); }, [childReportID, transactionsMergeParams, taxData, currentUserAccountID, currentUserLogin, isSuperWideRHPDisplayed]); const handleResolveDuplicates = useCallback(() => {