Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Not found page shows briefly when deleting a track expense #53408

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ function goBack(fallbackRoute?: Route, shouldEnforceFallback = false, shouldPopT

if (shouldPopToTop) {
if (shouldPopAllStateOnUP) {
const rootState = navigationRef.getRootState();
shouldPopAllStateOnUP = false;
navigationRef.current?.dispatch(StackActions.popToTop());
navigationRef.current?.dispatch({...StackActions.popToTop(), target: rootState.key});
return;
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/pages/Debug/Report/DebugReportPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useCallback, useMemo} from 'react';
import {View} from 'react-native';
import {InteractionManager, View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import Button from '@components/Button';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
Expand All @@ -10,7 +10,7 @@ import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {navigateToConciergeChatAndDeleteReport} from '@libs/actions/Report';
import {deleteReport} from '@libs/actions/Report';
import DebugUtils from '@libs/DebugUtils';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import type {DebugTabNavigatorRoutes} from '@libs/Navigation/DebugTabNavigator';
Expand Down Expand Up @@ -123,7 +123,12 @@ function DebugReportPage({
Debug.setDebugData(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, data);
}}
onDelete={() => {
navigateToConciergeChatAndDeleteReport(reportID, true, true);
Navigation.resetToHome();
// We need to wait for navigation animations to finish before deleting an action,
// otherwise the user will see a not found page briefly.
InteractionManager.runAfterInteractions(() => {
deleteReport(reportID, true);
});
}}
validate={DebugUtils.validateReportDraftProperty}
>
Expand Down
18 changes: 15 additions & 3 deletions src/pages/home/report/withReportOrNotFound.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable rulesdir/no-negated-variables */
import {useIsFocused} from '@react-navigation/native';
import type {ComponentType, ForwardedRef, RefAttributes} from 'react';
import React, {useEffect} from 'react';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import getComponentDisplayName from '@libs/getComponentDisplayName';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import * as ReportUtils from '@libs/ReportUtils';
import type {
Expand Down Expand Up @@ -66,10 +66,11 @@ export default function (
const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${props.route.params.reportID}`);
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA);
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${props.route.params.reportID}`);
const isFocused = useIsFocused();
const contentShown = React.useRef(false);
const wasReportAccessible = React.useRef(false);
const isReportIdInRoute = !!props.route.params.reportID?.length;
const isReportLoaded = !isEmptyObject(report) && !!report?.reportID;
const canAccessReport = isReportLoaded && ReportUtils.canAccessReport(report, policies, betas);

// The `isLoadingInitialReportActions` value will become `false` only after the first OpenReport API call is finished (either succeeded or failed)
const shouldFetchReport = isReportIdInRoute && reportMetadata?.isLoadingInitialReportActions !== false;
Expand All @@ -86,14 +87,25 @@ export default function (
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [shouldFetchReport, isReportLoaded, props.route.params.reportID]);

// Track when we lose access to a previously accessible report
useEffect(() => {
if (canAccessReport) {
wasReportAccessible.current = true;
} else if (wasReportAccessible.current && !canAccessReport) {
// If we previously had access but lost it, reset to home in order to avoid
// being stuck on blank page or get infinite report skeleton loading
Navigation.resetToHome();
}
}, [canAccessReport]);

if (shouldRequireReportID || isReportIdInRoute) {
const shouldShowFullScreenLoadingIndicator = !isReportLoaded && (isLoadingReportData !== false || shouldFetchReport);
const shouldShowNotFoundPage = !isReportLoaded || !ReportUtils.canAccessReport(report, policies, betas);

// If the content was shown, but it's not anymore, that means the report was deleted, and we are probably navigating out of this screen.
// Return null for this case to avoid rendering FullScreenLoadingIndicator or NotFoundPage when animating transition.
// eslint-disable-next-line react-compiler/react-compiler
if (shouldShowNotFoundPage && contentShown.current && !isFocused) {
if (shouldShowNotFoundPage && contentShown.current) {
return null;
}

Expand Down
Loading