Skip to content

Commit 29a54a1

Browse files
luacmartinsOSBotify
authored andcommitted
Merge pull request #89295 from Expensify/claude-fixMagicLinkNavigationReset
Skip prepending TabNavigator for public screens in navigation state (cherry picked from commit 52e86b7) (cherry-picked to staging by luacmartins)
1 parent 5d4fc1a commit 29a54a1

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/libs/Navigation/helpers/getAdaptedStateFromPath.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ const getRoutesWithIndex = (routes: NavigationPartialRoute[]): PartialState<Navi
3434
/** All tab routes derived from the shared TAB_SCREENS constant. */
3535
const TAB_NAVIGATOR_ROUTES: NavigationPartialRoute[] = TAB_SCREENS.map((name) => ({name}));
3636

37+
/**
38+
* Screens that are registered in PublicScreens (unauthenticated navigator) and should not
39+
* have TabNavigator prepended, because when the user is unauthenticated TabNavigator does
40+
* not exist in the navigator tree and the RESET action would fail.
41+
*
42+
* Keep in sync with the screens registered in PublicScreens.tsx (excluding SCREENS.HOME,
43+
* which doubles as the authenticated home tab, and navigator entries).
44+
*/
45+
const PUBLIC_SCREENS = new Set<string>([
46+
SCREENS.VALIDATE_LOGIN,
47+
SCREENS.TRANSITION_BETWEEN_APPS,
48+
SCREENS.CONNECTION_COMPLETE,
49+
SCREENS.BANK_CONNECTION_COMPLETE,
50+
SCREENS.UNLINK_LOGIN,
51+
SCREENS.SAML_SIGN_IN,
52+
]);
53+
3754
/**
3855
* Builds TabNavigator state with all tabs and the correct selected tab.
3956
* Tab navigators require all routes in the state for proper rendering.
@@ -355,6 +372,14 @@ function getAdaptedState(state: PartialState<NavigationState<RootNavigatorParamL
355372
return getRoutesWithIndex([getTabNavigatorState({name: NAVIGATORS.REPORTS_SPLIT_NAVIGATOR}), ...currentState.routes]);
356373
}
357374

375+
// Public screens (e.g. ValidateLogin) exist in both PublicScreens and AuthScreens navigators.
376+
// Don't prepend TabNavigator because when the user is unauthenticated, PublicScreens is active
377+
// and TabNavigator doesn't exist — causing the RESET action to fail.
378+
const hasOnlyPublicScreens = currentState.routes.every((route) => PUBLIC_SCREENS.has(route.name));
379+
if (hasOnlyPublicScreens) {
380+
return currentState;
381+
}
382+
358383
const defaultFullScreenRoute = getDefaultFullScreenRoute(focusedRoute);
359384

360385
// If not, add the default full screen route.

0 commit comments

Comments
 (0)