Skip to content

Commit 2ea1e8d

Browse files
committed
fix: Expensify#88963 - fallback to split navigator's default route when no existingFirstRoute
1 parent f8263d4 commit 2ea1e8d

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Log from '@libs/Log';
55
import buildTabNavigatorNestedState from '@libs/Navigation/helpers/buildTabNavigatorNestedState';
66
import getStateFromPath from '@libs/Navigation/helpers/getStateFromPath';
77
import {isFullScreenName} from '@libs/Navigation/helpers/isNavigatorName';
8-
import {SIDEBAR_TO_SPLIT} from '@libs/Navigation/linkingConfig/RELATIONS';
8+
import {SIDEBAR_TO_SPLIT, SPLIT_TO_SIDEBAR} from '@libs/Navigation/linkingConfig/RELATIONS';
99
import type {NavigationPartialRoute} from '@libs/Navigation/types';
1010
import CONST from '@src/CONST';
1111
import NAVIGATORS from '@src/NAVIGATORS';
@@ -364,14 +364,19 @@ function handleReplaceFullscreenUnderRHP(
364364
}
365365
// Prepend the existing sidebar/root route (e.g. Inbox) to the incoming state when
366366
// it starts with a different screen, so back navigation from the new screen
367-
// lands on the sidebar.
367+
// lands on the sidebar. When the existing tab doesn't have nested
368+
// routes (e.g. cold-start through a deep link that opens straight into a modal),
369+
// fall back to the split navigator's default sidebar route so there is still
370+
// something to pop back to.
368371
let mergedNestedState = focusedTargetTab.state;
369372
const existingNestedRoutes = (r.state as PartialState<NavigationState> | undefined)?.routes;
370373
const newNestedRoutes = focusedTargetTab.state?.routes;
371374
const existingFirstRoute = existingNestedRoutes?.at(0);
372375
const newFirstRoute = newNestedRoutes?.at(0);
373-
if (existingFirstRoute && newFirstRoute && existingFirstRoute.name !== newFirstRoute.name) {
374-
const prependedRoutes = [existingFirstRoute, ...(newNestedRoutes ?? [])];
376+
const defaultSidebarRouteName = r.name in SPLIT_TO_SIDEBAR ? SPLIT_TO_SIDEBAR[r.name as keyof typeof SPLIT_TO_SIDEBAR] : undefined;
377+
const sidebarRoute: NavigationPartialRoute | undefined = existingFirstRoute ?? (defaultSidebarRouteName ? {name: defaultSidebarRouteName} : undefined);
378+
if (sidebarRoute && newFirstRoute && sidebarRoute.name !== newFirstRoute.name) {
379+
const prependedRoutes = [sidebarRoute, ...(newNestedRoutes ?? [])];
375380
mergedNestedState = {...focusedTargetTab.state, routes: prependedRoutes, index: prependedRoutes.length - 1};
376381
}
377382
return {

0 commit comments

Comments
 (0)