diff --git a/src/pages/iou/request/IOURequestStartPage.tsx b/src/pages/iou/request/IOURequestStartPage.tsx index b45f504e82479..a1c94aac30071 100644 --- a/src/pages/iou/request/IOURequestStartPage.tsx +++ b/src/pages/iou/request/IOURequestStartPage.tsx @@ -70,6 +70,17 @@ function IOURequestStartPage({ const isFromGlobalCreate = isEmptyObject(report?.reportID); const prevTransactionReportID = usePrevious(transaction?.reportID); + // Clear out the temporary expense if the reportID in the URL has changed from the transaction's reportID. + useFocusEffect( + useCallback(() => { + // The test transaction can change the reportID of the transaction on the flow so we should prevent the reportID from being reverted again. + if (transaction?.reportID === reportID || isLoadingSelectedTab || prevTransactionReportID !== transaction?.reportID) { + return; + } + initMoneyRequest(reportID, policy, isFromGlobalCreate, transaction?.iouRequestType, transactionRequestType); + }, [transaction, policy, reportID, isFromGlobalCreate, transactionRequestType, isLoadingSelectedTab, prevTransactionReportID]), + ); + useEffect(() => { Performance.markEnd(CONST.TIMING.OPEN_CREATE_EXPENSE); }, []); @@ -88,16 +99,6 @@ function IOURequestStartPage({ [policy, reportID, isFromGlobalCreate, transaction], ); - useFocusEffect( - useCallback(() => { - // The test transaction can change the reportID of the transaction on the flow so we should prevent the reportID from being reverted again. - if (isLoadingSelectedTab || prevTransactionReportID !== transaction?.reportID) { - return; - } - resetIOUTypeIfChanged(transactionRequestType); - }, [transaction?.reportID, resetIOUTypeIfChanged, transactionRequestType, isLoadingSelectedTab, prevTransactionReportID]), - ); - const [headerWithBackBtnContainerElement, setHeaderWithBackButtonContainerElement] = useState(null); const [tabBarContainerElement, setTabBarContainerElement] = useState(null); const [activeTabContainerElement, setActiveTabContainerElement] = useState(null);