diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 14041fbe35ce..41b49ff6e476 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4212,6 +4212,10 @@ function canAccessReport(report: OnyxEntry, policies: OnyxCollection key !== 'notFound'); + const shouldHideReport = !hasHelpfulErrors && !ReportUtils.canAccessReport(report, policies, betas); + const isLoading = !reportIDFromRoute || !isSidebarLoaded || PersonalDetailsUtils.isPersonalDetailsEmpty(); const lastReportAction: OnyxEntry = useMemo( () => @@ -356,8 +361,12 @@ function ReportScreen({ return; } + if (!shouldFetchReport(report)) { + return; + } + fetchReport(); - }, [report.reportID, reportMetadata?.isLoadingInitialReportActions, 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 520a9a3604c5..c74bb40a18b6 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -17,6 +17,7 @@ import Performance from '@libs/Performance'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import {isUserCreatedPolicyRoom} from '@libs/ReportUtils'; import {didUserLogInDuringSession} from '@libs/SessionUtils'; +import shouldFetchReport from '@libs/shouldFetchReport'; import {ReactionListContext} from '@pages/home/ReportScreenContext'; import * as Report from '@userActions/Report'; import Timing from '@userActions/Timing'; @@ -24,7 +25,6 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; import type * as OnyxTypes from '@src/types/onyx'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; import getInitialPaginationSize from './getInitialPaginationSize'; import PopoverReactionList from './ReactionList/PopoverReactionList'; import ReportActionsList from './ReportActionsList'; @@ -113,15 +113,21 @@ function ReportActionsView({ const isReportFullyVisible = useMemo((): boolean => getIsReportFullyVisible(isFocused), [isFocused]); const openReportIfNecessary = () => { - const createChatError = report.errorFields?.createChat; - // If the report is optimistic (AKA not yet created) we don't need to call openReport again - if (!!report.isOptimisticReport || !isEmptyObject(createChatError)) { + if (!shouldFetchReport(report)) { return; } Report.openReport(reportID, reportActionID); }; + const reconnectReportIfNecessary = () => { + if (!shouldFetchReport(report)) { + return; + } + + Report.reconnect(reportID); + }; + useLayoutEffect(() => { setCurrentReportActionID(''); }, [route]); @@ -223,7 +229,7 @@ function ReportActionsView({ if (isReportFullyVisible) { openReportIfNecessary(); } else { - Report.reconnect(reportID); + reconnectReportIfNecessary(); } } // update ref with current network state @@ -237,7 +243,7 @@ function ReportActionsView({ if (isReportFullyVisible) { openReportIfNecessary(); } else { - Report.reconnect(reportID); + reconnectReportIfNecessary(); } } // eslint-disable-next-line react-hooks/exhaustive-deps