diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 002c522d2b72..778679836085 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -12145,12 +12145,37 @@ function saveSplitTransactions(draftTransaction: OnyxEntry removeDraftSplitTransaction(originalTransactionID)); + const isSearchPageTopmostFullScreenRoute = isSearchTopmostFullScreenRoute(); + const transactionThreadReportID = iouActions.at(0)?.childReportID; + const transactionThreadReportScreen = Navigation.getReportRouteByID(transactionThreadReportID); + if (isSearchPageTopmostFullScreenRoute || !transactionReport?.parentReportID) { Navigation.dismissModal(); + + // After the modal is dismissed, remove the transaction thread report screen + // to avoid navigating back to a report removed by the split transaction. + requestAnimationFrame(() => { + if (!transactionThreadReportScreen?.key) { + return; + } + + Navigation.removeScreenByKey(transactionThreadReportScreen.key); + }); + return; } Navigation.dismissModalWithReport({reportID: expenseReport?.reportID ?? String(CONST.DEFAULT_NUMBER_ID)}); + + // After the modal is dismissed, remove the transaction thread report screen + // to avoid navigating back to a report removed by the split transaction. + requestAnimationFrame(() => { + if (!transactionThreadReportScreen?.key) { + return; + } + + Navigation.removeScreenByKey(transactionThreadReportScreen.key); + }); } export {