diff --git a/src/libs/Navigation/AppNavigator/createCustomFullScreenNavigator/CustomFullScreenRouter.tsx b/src/libs/Navigation/AppNavigator/createCustomFullScreenNavigator/CustomFullScreenRouter.tsx index e09de8fce287..fa4b22c4ac98 100644 --- a/src/libs/Navigation/AppNavigator/createCustomFullScreenNavigator/CustomFullScreenRouter.tsx +++ b/src/libs/Navigation/AppNavigator/createCustomFullScreenNavigator/CustomFullScreenRouter.tsx @@ -16,16 +16,16 @@ function adaptStateIfNecessary(state: StackState) { workspaceCentralPane?.params && 'policyID' in workspaceCentralPane.params && typeof workspaceCentralPane.params.policyID === 'string' ? workspaceCentralPane.params.policyID : undefined; + const policy = PolicyUtils.getPolicy(policyID ?? ''); + const isLoadingReportData = PolicyUtils.getIsLoadingReportData(); + const isPolicyAccessible = PolicyUtils.isPolicyAccessible(policy); // There should always be WORKSPACE.INITIAL screen in the state to make sure go back works properly if we deeplinkg to a subpage of settings. // The only exception is when the workspace is invalid or inaccessible. if (!isAtLeastOneInState(state, SCREENS.WORKSPACE.INITIAL)) { - const policy = PolicyUtils.getPolicy(policyID ?? ''); - const isPolicyAccessible = PolicyUtils.isPolicyAccessible(policy); - if (!isPolicyAccessible) { + if (isNarrowLayout && !isLoadingReportData && !isPolicyAccessible) { return; } - // @ts-expect-error Updating read only property // noinspection JSConstantReassignment state.stale = true; // eslint-disable-line diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 2ca572395aca..707a8387e103 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -1071,8 +1071,12 @@ function getActivePolicy(): OnyxEntry { return getPolicy(activePolicyId); } -function isPolicyAccessible(policy: OnyxEntry) { - return !isLoadingReportData && !isEmptyObject(policy) && (Object.keys(policy).length !== 1 || isEmptyObject(policy.errors)) && policy?.id; +function isPolicyAccessible(policy: OnyxEntry): boolean { + return !isEmptyObject(policy) && (Object.keys(policy).length !== 1 || isEmptyObject(policy.errors)) && !!policy?.id; +} + +function getIsLoadingReportData() { + return isLoadingReportData; } export { @@ -1193,6 +1197,7 @@ export { getAllPoliciesLength, getActivePolicy, isPolicyAccessible, + getIsLoadingReportData, }; export type {MemberEmailsToAccountIDs}; diff --git a/src/pages/workspace/AccessOrNotFoundWrapper.tsx b/src/pages/workspace/AccessOrNotFoundWrapper.tsx index 952378f4ce14..452bf27e6570 100644 --- a/src/pages/workspace/AccessOrNotFoundWrapper.tsx +++ b/src/pages/workspace/AccessOrNotFoundWrapper.tsx @@ -165,11 +165,11 @@ function AccessOrNotFoundWrapper({ const childrenProps = useMemo(() => ({report, policy, isLoadingReportData}), [report, policy, isLoadingReportData]); useEffect(() => { - if (!isPolicyNotAccessible) { + if (isLoadingReportData || !isPolicyNotAccessible) { return; } Navigation.removeScreenFromNavigationState(SCREENS.WORKSPACE.INITIAL); - }, [isPolicyNotAccessible]); + }, [isLoadingReportData, isPolicyNotAccessible]); if (shouldShowFullScreenLoadingIndicator) { return ;