Skip to content

Commit

Permalink
Merge pull request #41427 from bernhardoj/fix/39673-prevent-multiple-…
Browse files Browse the repository at this point in the history
…open-report

#2 - Fix multiple open report call when report screen is mounted
  • Loading branch information
flodnv authored May 14, 2024
2 parents 4d8b7fd + 3f124c7 commit 56ca21c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
14 changes: 5 additions & 9 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,19 +434,12 @@ 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, reportMetadata?.isLoadingInitialReportActions, fetchReport, reportIDFromRoute]);
}, [report, fetchReport, reportIDFromRoute]);

const dismissBanner = useCallback(() => {
setIsBannerVisible(false);
Expand All @@ -473,7 +466,10 @@ function ReportScreen({
Timing.end(CONST.TIMING.CHAT_RENDER);
Performance.markEnd(CONST.TIMING.CHAT_RENDER);

fetchReportIfNeeded();
// Call OpenReport only if we are not linking to a message or the report is not available yet
if (!reportActionIDFromRoute || !report.reportID) {
fetchReportIfNeeded();
}
const interactionTask = InteractionManager.runAfterInteractions(() => {
ComposerActions.setShouldShowComposeInput(true);
});
Expand Down
18 changes: 0 additions & 18 deletions src/pages/home/report/ReportActionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,6 @@ 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;
Expand Down

0 comments on commit 56ca21c

Please sign in to comment.