diff --git a/src/pages/inbox/ReportScreen.tsx b/src/pages/inbox/ReportScreen.tsx index b6b968974789e..07d1b671bf72b 100644 --- a/src/pages/inbox/ReportScreen.tsx +++ b/src/pages/inbox/ReportScreen.tsx @@ -540,12 +540,6 @@ function ReportScreen({route, navigation, isInSidePanel = false}: ReportScreenPr return; } - // If there is one transaction thread that has not yet been created, we should create it. - if (transactionThreadReportID === CONST.FAKE_REPORT_ID && !transactionThreadReport) { - createOneTransactionThreadReport(); - return; - } - // When a user goes through onboarding for the first time, various tasks are created for chatting with Concierge. // If this function is called too early (while the application is still loading), we will not have information about policies, // which means we will not be able to obtain the correct link for one of the tasks. @@ -561,20 +555,7 @@ function ReportScreen({route, navigation, isInSidePanel = false}: ReportScreenPr } openReport(reportIDFromRoute, introSelected, reportActionIDFromRoute); - }, [ - reportMetadata.isOptimisticReport, - report, - isOffline, - transactionThreadReportID, - transactionThreadReport, - reportIDFromRoute, - reportActionIDFromRoute, - createOneTransactionThreadReport, - isLoadingApp, - introSelected, - isOnboardingCompleted, - isInviteOnboardingComplete, - ]); + }, [reportMetadata.isOptimisticReport, report, isOffline, isLoadingApp, introSelected, isOnboardingCompleted, isInviteOnboardingComplete, reportIDFromRoute, reportActionIDFromRoute]); useEffect(() => { if (!isAnonymousUser) { @@ -583,6 +564,15 @@ function ReportScreen({route, navigation, isInSidePanel = false}: ReportScreenPr prevIsAnonymousUser.current = true; }, [isAnonymousUser]); + useEffect(() => { + if (transactionThreadReportID !== CONST.FAKE_REPORT_ID || transactionThreadReport?.reportID || (!reportMetadata.hasOnceLoadedReportActions && !reportMetadata?.isOptimisticReport)) { + return; + } + + createOneTransactionThreadReport(); + // eslint-disable-next-line react-hooks/exhaustive-deps -- we don't want to run this useEffect when createOneTransactionThreadReport changes + }, [reportMetadata.hasOnceLoadedReportActions, reportMetadata?.isOptimisticReport, transactionThreadReport?.reportID, transactionThreadReportID]); + useEffect(() => { if (isLoadingReportData || !prevIsLoadingReportData || !prevIsAnonymousUser.current || isAnonymousUser) { return;