@@ -2,12 +2,13 @@ import {useEffect, useRef} from 'react';
22import { InteractionManager } from 'react-native' ;
33import { startOnboardingFlow } from '@libs/actions/Welcome/OnboardingFlow' ;
44import getCurrentUrl from '@libs/Navigation/currentUrl' ;
5- import Navigation from '@libs/Navigation/Navigation' ;
5+ import Navigation , { navigationRef } from '@libs/Navigation/Navigation' ;
66import { hasCompletedGuidedSetupFlowSelector , tryNewDotOnyxSelector } from '@libs/onboardingSelectors' ;
77import { buildCannedSearchQuery } from '@libs/SearchQueryUtils' ;
88import { isLoggingInAsNewUser } from '@libs/SessionUtils' ;
99import isProductTrainingElementDismissed from '@libs/TooltipUtils' ;
1010import CONFIG from '@src/CONFIG' ;
11+ import NAVIGATORS from '@src/NAVIGATORS' ;
1112import ONYXKEYS from '@src/ONYXKEYS' ;
1213import ROUTES from '@src/ROUTES' ;
1314import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue' ;
@@ -61,11 +62,17 @@ function useOnboardingFlowRouter() {
6162 if ( CONFIG . IS_HYBRID_APP && isLoadingOnyxValue ( isSingleNewDotEntryMetadata ) ) {
6263 return ;
6364 }
65+
6466 if ( hasBeenAddedToNudgeMigration && ! isProductTrainingElementDismissed ( 'migratedUserWelcomeModal' , dismissedProductTraining ) ) {
65- const defaultCannedQuery = buildCannedSearchQuery ( ) ;
66- const query = defaultCannedQuery ;
67- Navigation . navigate ( ROUTES . SEARCH_ROOT . getRoute ( { query} ) ) ;
68- Navigation . navigate ( ROUTES . MIGRATED_USER_WELCOME_MODAL . getRoute ( true ) ) ;
67+ const navigationState = navigationRef . getRootState ( ) ;
68+ const lastRoute = navigationState . routes . at ( - 1 ) ;
69+ // Prevent duplicate navigation if the migrated user modal is already shown.
70+ if ( lastRoute ?. name !== NAVIGATORS . MIGRATED_USER_MODAL_NAVIGATOR ) {
71+ const defaultCannedQuery = buildCannedSearchQuery ( ) ;
72+ const query = defaultCannedQuery ;
73+ Navigation . navigate ( ROUTES . SEARCH_ROOT . getRoute ( { query} ) ) ;
74+ Navigation . navigate ( ROUTES . MIGRATED_USER_WELCOME_MODAL . getRoute ( true ) ) ;
75+ }
6976 return ;
7077 }
7178
0 commit comments