-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Skip prepending TabNavigator for public screens in navigation state #89295
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,23 @@ const getRoutesWithIndex = (routes: NavigationPartialRoute[]): PartialState<Navi | |
| /** All tab routes derived from the shared TAB_SCREENS constant. */ | ||
| const TAB_NAVIGATOR_ROUTES: NavigationPartialRoute[] = TAB_SCREENS.map((name) => ({name})); | ||
|
|
||
| /** | ||
| * Screens that are registered in PublicScreens (unauthenticated navigator) and should not | ||
| * have TabNavigator prepended, because when the user is unauthenticated TabNavigator does | ||
| * not exist in the navigator tree and the RESET action would fail. | ||
| * | ||
| * Keep in sync with the screens registered in PublicScreens.tsx (excluding SCREENS.HOME, | ||
| * which doubles as the authenticated home tab, and navigator entries). | ||
| */ | ||
| const PUBLIC_SCREENS = new Set<string>([ | ||
| SCREENS.VALIDATE_LOGIN, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CONSISTENCY-3 (docs)The Consider extracting a shared constant (e.g., an array of public screen names) that both Reviewed at: 5b9d535 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree but let's do this as follow-up. Since this PR will be CP'ed to staging, the code should be minimal. |
||
| SCREENS.TRANSITION_BETWEEN_APPS, | ||
| SCREENS.CONNECTION_COMPLETE, | ||
| SCREENS.BANK_CONNECTION_COMPLETE, | ||
| SCREENS.UNLINK_LOGIN, | ||
| SCREENS.SAML_SIGN_IN, | ||
| ]); | ||
|
|
||
| /** | ||
| * Builds TabNavigator state with all tabs and the correct selected tab. | ||
| * Tab navigators require all routes in the state for proper rendering. | ||
|
|
@@ -355,6 +372,14 @@ function getAdaptedState(state: PartialState<NavigationState<RootNavigatorParamL | |
| return getRoutesWithIndex([getTabNavigatorState({name: NAVIGATORS.REPORTS_SPLIT_NAVIGATOR}), ...currentState.routes]); | ||
| } | ||
|
|
||
| // Public screens (e.g. ValidateLogin) exist in both PublicScreens and AuthScreens navigators. | ||
| // Don't prepend TabNavigator because when the user is unauthenticated, PublicScreens is active | ||
| // and TabNavigator doesn't exist — causing the RESET action to fail. | ||
| const hasOnlyPublicScreens = currentState.routes.every((route) => PUBLIC_SCREENS.has(route.name)); | ||
| if (hasOnlyPublicScreens) { | ||
| return currentState; | ||
|
Comment on lines
+378
to
+380
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This unconditional early return for Useful? React with 👍 / 👎.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| const defaultFullScreenRoute = getDefaultFullScreenRoute(focusedRoute); | ||
|
|
||
| // If not, add the default full screen route. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ CONSISTENCY-3 (docs)
The
PUBLIC_SCREENSset is a hardcoded list that duplicates information already defined elsewhere. The exact same six screens are listed in thePublicScreenNametype union insrc/libs/Navigation/types.ts(line 3266-3272), and the comment itself acknowledges this by saying "Keep in sync with the screens registered in PublicScreens.tsx" -- a manual sync requirement is a strong indicator of a DRY violation.Consider creating a single source-of-truth runtime array (e.g.,
const PUBLIC_SCREEN_NAMES = [SCREENS.VALIDATE_LOGIN, SCREENS.TRANSITION_BETWEEN_APPS, SCREENS.CONNECTION_COMPLETE, SCREENS.BANK_CONNECTION_COMPLETE, SCREENS.UNLINK_LOGIN, SCREENS.SAML_SIGN_IN] as const) in a shared location, then deriving both thePublicScreenNametype (viatypeof PUBLIC_SCREEN_NAMES[number]) and thisSetfrom it. This eliminates the risk of the two lists drifting out of sync.Reviewed at: 5b9d535 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.