From 159cadb29014df4a926827678ee257ab6db3aa79 Mon Sep 17 00:00:00 2001 From: Francois Laithier Date: Tue, 30 Apr 2024 10:58:10 -0700 Subject: [PATCH] Revert "Merge pull request #40624 from bernhardoj/fix/39673-prevent-multiple-open-report" This reverts commit c3435523bc3f655268c3f9a348da84996e5d3a61, reversing changes made to c4d9d4eb847fe96bfade7f7cdb533d27bbc56d86. --- src/pages/home/ReportScreen.tsx | 9 ++++++++- src/pages/home/report/ReportActionsView.tsx | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index aa7c623ac2b4..d84d610a171a 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -426,12 +426,19 @@ function ReportScreen({ return; } + // It is possible that we may not have the report object yet in Onyx yet e.g. we navigated to a URL for an accessible report that + // is not stored locally yet. If report.reportID exists, then the report has been stored locally and nothing more needs to be done. + // If it doesn't exist, then we fetch the report from the API. + if (report.reportID && report.reportID === reportIDFromRoute && !reportMetadata?.isLoadingInitialReportActions) { + return; + } + if (!shouldFetchReport(report)) { return; } fetchReport(); - }, [report, fetchReport, reportIDFromRoute]); + }, [report, reportMetadata?.isLoadingInitialReportActions, fetchReport, reportIDFromRoute]); const dismissBanner = useCallback(() => { setIsBannerVisible(false); diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 3552ac16b236..cb904327e625 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -237,6 +237,24 @@ function ReportActionsView({ const oldestReportAction = useMemo(() => reportActions?.at(-1), [reportActions]); const hasCreatedAction = oldestReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED; + useEffect(() => { + if (reportActionID) { + return; + } + + const interactionTask = InteractionManager.runAfterInteractions(() => { + openReportIfNecessary(); + }); + // eslint-disable-next-line @typescript-eslint/no-misused-promises + if (interactionTask) { + return () => { + interactionTask.cancel(); + }; + } + + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + useEffect(() => { if (!reportActionID || indexOfLinkedAction > -1) { return;