Skip to content
Merged
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
13 changes: 11 additions & 2 deletions src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {isFullScreenName, isOnboardingFlowName, isSplitNavigatorName} from './he
import isReportOpenInRHP from './helpers/isReportOpenInRHP';
import isReportTopmostSplitNavigator from './helpers/isReportTopmostSplitNavigator';
import isSideModalNavigator from './helpers/isSideModalNavigator';
import isTabNavigatorReady from './helpers/isTabNavigatorReady';
import linkTo from './helpers/linkTo';
import getMinimalAction from './helpers/linkTo/getMinimalAction';
import type {LinkToOptions} from './helpers/linkTo/types';
Expand Down Expand Up @@ -698,8 +699,16 @@ function navContainsProtectedRoutes(state: State | undefined): boolean {
return false;
}

// If one protected screen is in the routeNames then other screens are there as well.
return state?.routeNames.includes(PROTECTED_SCREENS.CONCIERGE);
if (!state.routeNames.includes(PROTECTED_SCREENS.CONCIERGE)) {
return false;
}

// routeNames only tells us screens are declared on the root navigator.
// We also need TabNavigator to be mounted (its child router has run
// useNavigationBuilder and produced a non-stale nested state), otherwise a
// deferred NAVIGATE targeting a screen inside TabNavigator will be dispatched
// before any child router is registered to handle it.
return isTabNavigatorReady(state);
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/libs/Navigation/helpers/isTabNavigatorReady.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type {NavigationState, PartialState} from '@react-navigation/native';
import NAVIGATORS from '@src/NAVIGATORS';

/**
* Checks whether TabNavigator's child router has mounted and produced a
* non-stale nested state. Until `useNavigationBuilder` runs inside
* TabNavigator, the route's nested state stays `stale: true` and React
* Navigation cannot handle NAVIGATE actions targeting screens inside it.
*/
function isTabNavigatorReady(state: NavigationState | PartialState<NavigationState> | undefined): boolean {
const tabRoute = state?.routes?.find((route) => route.name === NAVIGATORS.TAB_NAVIGATOR);
return tabRoute?.state?.stale === false;
}

export default isTabNavigatorReady;
11 changes: 11 additions & 0 deletions src/libs/Navigation/linkingConfig/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {LinkingOptions} from '@react-navigation/native';
import {findFocusedRoute} from '@react-navigation/native';
import {Linking} from 'react-native';
import continuePlaidOAuth from '@libs/continuePlaidOAuth';
import isTabNavigatorReady from '@libs/Navigation/helpers/isTabNavigatorReady';
import navigationRef from '@libs/Navigation/navigationRef';
import type {RootNavigatorParamList} from '@libs/Navigation/types';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -31,6 +32,16 @@ const subscribe: LinkingOptions<RootNavigatorParamList>['subscribe'] = (listener
continuePlaidOAuth(url);
return;
}
// Skip forwarding URLs while TabNavigator is mounting — its child
// router hasn't run useNavigationBuilder yet, so React Navigation
// can't handle nested NAVIGATE actions and throws an unhandled-action
// error. Protected-screen deep links will be handled separately by
// openReportFromDeepLink via waitForProtectedRoutes().
const state = navigationRef.current?.getRootState();
if (!isTabNavigatorReady(state)) {
return;
}

listener(url);
});
return () => subscription.remove();
Expand Down
Loading