App icon indicating copy to clipboard operation
App copied to clipboard

[$250] Onboarding-Onboarding is displayed for invited to the workspace account

Open applause-bot[bot] opened this issue 2 weeks ago • 92 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.5.39-2 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/tc/TC-4280 Email or phone of affected tester (no customers): N/A Issue reported by: Applause Internal Team Bug source: Regression TC Execution Device used: MacBook Air 26.6.2 Chrome, iPhone 15 iOS 26.6.1 App Component: Other

Action Performed:

  1. Go to OldDot staging.expensify.com
  2. Choose the "Manage expenses for 1-9 employees" option and sign up with a new account
  3. Once on NewDot - don't complete the onboarding modal, close the window
  4. As another account invite the created account to a Collect workspace in OldDot as a member
  5. As the invited member, open staging.new.expensify.com Verify the onboarding modal is not displayed

Expected Result:

The onboarding modal is not displayed

Actual Result:

Onboarding is displayed for invited to the workspace as a member account

Workaround:

Unknown

Platforms:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [x] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [x] MacOS: Chrome Safari

Screenshots/Videos

https://github.com/user-attachments/assets/be5b6295-e349-4223-bfdd-f27a8544d4e2

View all open jobs on GitHub

Applause Internal Information Exported by: Nathan Lemma Bug ID: 7313593

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @sam5235

applause-bot[bot] avatar Nov 14 '26 13:11 applause-bot[bot]

While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/ca185dd7209c6984fd5926b35616f52e67a3d85dd1b5bdf7ee5a0b23b8b5ab17

applause-bot[bot] avatar Nov 14 '26 13:11 applause-bot[bot]

Triggered auto assignment to Contributor-plus team member for initial proposal review - @ZhenjaHorbach (External)

melvin-bot[bot] avatar Nov 14 '26 13:11 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~022121594219771749048

melvin-bot[bot] avatar Nov 14 '26 13:11 melvin-bot[bot]

Investigation Progress:

  • [x] Step 1: Extract symptoms and identifiers
  • [x] Step 2: Form and revise hypothesis
  • [x] Step 3: Scan related issues and locate relevant code
  • [x] Step 4: Gather independent researcher findings
  • [x] Step 5: Evaluate the evidence
  • [x] Step 6: Challenge the hypothesis against cleanup behavior and existing tests
  • [ ] Step 7: Confirm the reported flow — blocked by unavailable OldDot/two-account test setup
  • [x] Step 8: Prepare preliminary analysis

The evidence supports a possible saved-route restoration problem, not a confirmed root cause. Blanket dismissal would conflict with tests that intentionally preserve onboarding when a user joins a workspace during an active flow.## Issue Analysis

⚠️ Preliminary analysis — low confidence in the issue-specific root cause.

Possible cause: NewDot may restore the abandoned onboarding screen when the invited user returns, rather than start onboarding through its normal eligibility checks.

Evidence

This could explain abandon onboarding → receive invitation → reopen NewDot → see onboarding again, provided the same browser session retained the saved route.

What remains unverified

Missing or delayed membership data is an alternative explanation. To distinguish it from route restoration, capture on reopening:

  • The launch URL and saved lastVisitedPath.
  • hasNonPersonalPolicy, introSelected.inviteType, and onboarding completion state.
  • Whether onboarding was restored or newly started.

Web verification was blocked, not a confirmed product failure: the tester could not establish the required OldDot signup and second-account invitation fixture. No production confirmation was obtained.

Fix assessment

No implementation-ready fix is established. Do not add another generic membership check or automatically dismiss every active onboarding flow: existing tests intentionally preserve onboarding when membership changes during an active flow (LinkOpenReportFromDeepLinkTest.ts:249–265).

Potentially related

Close onboarding after merging into an existing account also concerns onboarding remaining open after eligibility changes, but is not a confirmed duplicate.


Next Steps: Confirm the startup route and membership state before selecting a fix.


view run

MelvinBot avatar Nov 14 '26 13:11 MelvinBot

Proposal

What is the root cause of that problem?

The invited member never reaches the normal entry check; the abandoned onboarding screen is restored. NavigationRoot.tsx:94-96 saves every /onboarding... path via updateOnboardingLastVisitedPath and updateLastVisitedPath. On the next cold open (step 5: root URL, authenticated), NavigationRoot.tsx:177-186 returns getAdaptedStateFromPath(lastVisitedPath), which is the onboarding route. The only onboarding redirect in that initial-state block (NavigationRoot.tsx:155-159) fires for completed or suppressed users, never for invited members. After that, OnboardingGuard.ts:269 sets isInvitedOrGroupMember = hasNonPersonalPolicy || wasInvitedToNewDot, and OnboardingGuard.ts:312,319-321 turns that into ALLOW, so nothing pulls the user out. useOnboardingFlow.ts:116-119 also only stops starting onboarding, it never dismisses one already on screen.

What changes do you think we should make in order to solve the problem?

In the useState initializer of NavigationRoot, read hasNonPersonalPolicy (ONYXKEYS.HAS_NON_PERSONAL_POLICY) and wasInvitedToNewDotSelector(introSelected), the same inputs the guard uses, and extend the line-157 condition:

const isInvitedOrGroupMember = hasNonPersonalPolicy || wasInvitedToNewDot;
if ((isOnboardingCompleted || shouldSuppressPromotionalUI || isInvitedOrGroupMember) && shouldRedirectCompletedUser) {
    return getAdaptedStateFromPath(ROUTES.HOME);
}

Also skip restoring an onboarding lastVisitedPath at line 177 for these users (fall to HOME). This does not dismiss flows that are already open, so the join-during-active-flow tests in LinkOpenReportFromDeepLinkTest.ts stay valid. isJoinWorkspaceTaskPath keeps its exemption.

Test: extend tests/unit/NavigationRootInitialStateTest.tsx. Seed lastVisitedPath = /onboarding/purpose, authenticated, onboarding not completed. Assert initial state is HOME when HAS_NON_PERSONAL_POLICY is true, or introSelected.inviteType is set. Assert it is still the onboarding route for a plain new user.

What alternative solutions did you explore? (Optional)

MelvinBot's comment names the same restoration path but proposes no fix and warns against a blanket dismissal; this change is limited to startup and gives a concrete test. I considered making OnboardingGuard redirect invited members away from onboarding, but that breaks the intentional join-during-flow behaviour.

Stephen3453 avatar Nov 14 '26 13:11 Stephen3453

Proposal

What is the root cause of that problem?

When a user signs up on OldDot or NewDot and reaches the onboarding flow, NavigationRoot.tsx:93-96 saves the active route into Onyx:

updateLastVisitedPath(currentPath);
if (currentPath.startsWith(`/${ROUTES.ONBOARDING_ROOT.route}`)) {
    updateOnboardingLastVisitedPath(currentPath);
}

If the user abandons the tab without finishing onboarding, lastVisitedPath in Onyx remains an onboarding route (e.g. /onboarding/purpose).

When that user is later invited to a workspace as a member from OldDot, their session acquires hasNonPersonalPolicy = true (or introSelected with an invitation type). In useOnboardingFlow.ts:116-119 and OnboardingGuard.ts:269, this defines:

const isInvitedOrGroupMember = (hasNonPersonalPolicy || wasInvitedToNewDot) ?? false;

useOnboardingFlow.ts:117 correctly prevents automatically starting a new onboarding flow for invited members (if (isMigratedUser || isInvitedOrGroupMember || shouldSuppressPromotionalUI) return;).

However, on a cold launch to the root URL (step 5: https://staging.new.expensify.com/):

  1. In src/libs/Navigation/NavigationRoot.tsx:153-159, initialState computes:
    const path = initialUrl ? getPathFromURL(initialUrl) : null;
    const shouldRedirectCompletedUser = !!path && isOnboardingPath(path) && !isJoinWorkspaceTaskPath(path);
    if ((isOnboardingCompleted || shouldSuppressPromotionalUI) && shouldRedirectCompletedUser) {
        return getAdaptedStateFromPath(ROUTES.HOME);
    }
    
    • Because initialUrl is the root URL, path is / (not an onboarding path), so shouldRedirectCompletedUser is false.
    • Furthermore, line 157 only checks isOnboardingCompleted || shouldSuppressPromotionalUI, omitting isInvitedOrGroupMember.
  2. Execution falls through to line 177:
    if (shouldOpenLastVisitedPath(lastVisitedPath) && authenticated) {
        const isRootPath = !path || path === '' || path === '/';
        const isSpecificDeepLink = path && !isRootPath;
        if (!isSpecificDeepLink) {
            return getAdaptedStateFromPath(lastVisitedPath);
        }
    }
    
    lastVisitedPath (/onboarding/purpose) is unconditionally restored via getAdaptedStateFromPath(lastVisitedPath).
  3. Because computing initialState skips OnboardingGuard (as documented at line 156: // An initial state skips OnboardingGuard...), React Navigation mounts ONBOARDING_MODAL_NAVIGATOR immediately on startup. Once mounted, OnboardingGuard allows the focused navigator and blocks navigating away, permanently trapping the invited member in the abandoned onboarding modal.
  4. Additionally, in src/libs/Navigation/guards/OnboardingGuard.ts:273-301, while completed users, test builds, and promotional UI suppressed sessions are actively redirected away from onboarding (REDIRECT -> ROUTES.HOME), isInvitedOrGroupMember is only passed to shouldSkipOnboarding (returning ALLOW), which fails to redirect an invited member away if an onboarding action is initiated.

What changes do you think we should make in order to solve the problem?

  1. Guard lastVisitedPath restoration and initialState in src/libs/Navigation/NavigationRoot.tsx:

    • Subscribe to HAS_NON_PERSONAL_POLICY and NVP_INTRO_SELECTED to resolve isInvitedOrGroupMember:
      const [hasNonPersonalPolicy] = useOnyx(ONYXKEYS.HAS_NON_PERSONAL_POLICY);
      const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
      const isInvitedOrGroupMember = (hasNonPersonalPolicy || wasInvitedToNewDotSelector(introSelected)) ?? false;
      
    • In the initialState calculator (line 157), include isInvitedOrGroupMember alongside completed and suppressed users so any direct launch into onboarding routes redirects to ROUTES.HOME:
      if ((isOnboardingCompleted || shouldSuppressPromotionalUI || isInvitedOrGroupMember) && shouldRedirectCompletedUser) {
          return getAdaptedStateFromPath(ROUTES.HOME);
      }
      
    • In the lastVisitedPath restoration block (line 183), check if lastVisitedPath is an onboarding path (isOnboardingPath(lastVisitedPath) && !isJoinWorkspaceTaskPath(lastVisitedPath)). If the user is completed, promotional UI suppressed, or an invited/group member, do not restore the stale onboarding route; return getAdaptedStateFromPath(ROUTES.HOME) instead:
      if (!isSpecificDeepLink) {
          if (isOnboardingPath(lastVisitedPath) && !isJoinWorkspaceTaskPath(lastVisitedPath)) {
              if (isOnboardingCompleted || shouldSuppressPromotionalUI || isInvitedOrGroupMember) {
                  return getAdaptedStateFromPath(ROUTES.HOME);
              }
          }
      
          Log.info('Restoring last visited path on app startup', false, {lastVisitedPath, initialUrl, path});
          return getAdaptedStateFromPath(lastVisitedPath);
      }
      
  2. Redirect invited members away from onboarding in src/libs/Navigation/guards/OnboardingGuard.ts:

    • In OnboardingGuard.evaluate (after line 301), ensure any action attempting to navigate or replace into the onboarding flow redirects invited/group members to ROUTES.HOME (while preserving isJoinWorkspaceTaskRoute):
      if (isInvitedOrGroupMember && (isNavigatingToOnboardingFlow(action) || isNavigatingWithReplace) && !isNavigatingToJoinWorkspaceTaskRoute) {
          Log.info('[OnboardingGuard] Redirecting invited or group member away from onboarding route to home');
          return {type: 'REDIRECT', route: ROUTES.HOME};
      }
      
  3. Automated Unit Tests:

    • In tests/unit/NavigationRootInitialStateTest.tsx: Add unit test asserting that an invited workspace member (ONYXKEYS.HAS_NON_PERSONAL_POLICY: true) with an uncompleted onboarding state and an onboarding lastVisitedPath resolves its initial state to ROUTES.HOME on cold start without an initial URL.
    • In tests/unit/Navigation/guards/OnboardingGuard.test.ts: Add test asserting that OnboardingGuard.evaluate returns {type: 'REDIRECT', route: ROUTES.HOME} when an invited workspace member navigates to an onboarding route.

What alternative solutions did you explore? (Optional)

  • Clearing ONBOARDING_LAST_VISITED_PATH or LAST_VISITED_PATH in Onyx when policy membership changes: Discarded because lastVisitedPath is managed as a navigation history cursor across routes. Modifying startup state evaluation in NavigationRoot and guarding against onboarding in OnboardingGuard is declarative, handles cross-tab/reconnect updates, and avoids race conditions during initial Onyx hydration.
  • Relying solely on OnboardingGuard: Discarded because NavigationRoot's useState computes the initial state directly and passes it to NavigationContainer, which mounts the restored onboarding tree before OnboardingGuard evaluates navigation actions.

Contributor details

Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0131dae36abcf59374

kevinjosh10 avatar Nov 14 '26 13:11 kevinjosh10

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 14 '26 13:11 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

A user signs up via OldDot, opens NewDot without finishing onboarding, and closes the app. Another account invites them as a Collect workspace member. Reopening NewDot still shows the onboarding modal instead of landing in the app.

What is the root cause of that problem?

Two mechanisms race on cold reopen after an account is invited while the client is closed:

  1. Stale lastVisitedPath restoration bypasses onboarding eligibility checks:

    • During the incomplete session, parseAndLogRoute (src/libs/Navigation/NavigationRoot.tsx:92-97) saves /onboarding/... to ONYXKEYS.LAST_VISITED_PATH (line 93) and ONYXKEYS.ONBOARDING_LAST_VISITED_PATH (lines 94-96).
    • saveCurrentPathBeforeBackground (src/libs/actions/App.ts:250-260) also saves /onboarding/... to ONYXKEYS.LAST_VISITED_PATH (line 259) when backgrounding on mobile. SCREENS.ONBOARDING routes are absent from CONST.EXCLUDE_FROM_LAST_VISITED_PATH (src/CONST/runtimeConfigured.ts:68-82).
    • On reopen, src/Expensify.tsx:313-320 mounts NavigationRoot before AuthScreensInitHandler (src/libs/Navigation/AppNavigator/AuthScreensInitHandler.tsx:229) dispatches App.reconnectApp.
    • In NavigationRoot (src/libs/Navigation/NavigationRoot.tsx:153-191), a root URL (/ or null) skips shouldRedirectCompletedUser (line 155) and restores getAdaptedStateFromPath(lastVisitedPath) (lines 177-187) straight into OnboardingModalNavigator.
    • NavigationRoot (line 157) also omits isInvitedOrGroupMember, and cached Onyx still holds stale pre-invite values at mount time.
  2. Initial ReconnectApp does not gate OnboardingGuard or useOnboardingFlowRouter:

    • Because didUserLogInDuringSession() (src/libs/SessionUtils.ts:69-95) is false on cold reopen, AuthScreensInitHandler calls App.reconnectApp (src/libs/Navigation/AppNavigator/AuthScreensInitHandler.tsx:229).
    • reconnectApp passes isOpenApp = false to getOnyxDataForOpenOrReconnect (src/libs/actions/App.ts:350-356, 505), so ONYXKEYS.IS_LOADING_APP stays false while ReconnectApp is in flight.
    • OnboardingGuard.evaluate (src/libs/Navigation/guards/OnboardingGuard.ts:269, 304-357) reads GuardContext.isLoading from ONYXKEYS.IS_LOADING_APP (src/libs/Navigation/guards/index.ts:33-39, 64). Pre-sync root actions see isLoading = false and stale isInvitedOrGroupMember = false, redirecting HOME into onboarding (OnboardingGuard.ts:339-357).
    • useOnboardingFlowRouter (src/hooks/useOnboardingFlow.ts:84-86, 116-119, 142-146) gates only on isLoadingApp !== false || isOnboardingLoading (line 84). It can call startOnboardingFlow (line 144) before ReconnectApp returns HAS_NON_PERSONAL_POLICY = true.
    • Once OnboardingModalNavigator is mounted, receiving HAS_NON_PERSONAL_POLICY = true leaves the modal open. OnboardingGuard (OnboardingGuard.ts:312, 319-321) returns {type: 'ALLOW'} and useOnboardingFlowRouter (useOnboardingFlow.ts:116-119) returns early without dismissing it.

What changes do you think we should make in order to solve the problem?

  1. Stop persisting and restoring non-task onboarding routes in LAST_VISITED_PATH (src/libs/Navigation/NavigationRoot.tsx, src/libs/actions/App.ts):

    • In parseAndLogRoute (src/libs/Navigation/NavigationRoot.tsx:92-97), call updateLastVisitedPath(currentPath) only when !isOnboardingPath(currentPath) || isJoinWorkspaceTaskPath(currentPath). Keep updateOnboardingLastVisitedPath(currentPath) (lines 94-96) unchanged.
    • In saveCurrentPathBeforeBackground (src/libs/actions/App.ts:250-260), skip updateLastVisitedPath(currentPath) (line 259) when isOnboardingPath(currentPath) && !isJoinWorkspaceTaskPath(currentPath).
    • In NavigationRoot (src/libs/Navigation/NavigationRoot.tsx:146-187), subscribe to ONYXKEYS.HAS_NON_PERSONAL_POLICY and ONYXKEYS.NVP_INTRO_SELECTED (via wasInvitedToNewDotSelector). Add isInvitedOrGroupMember to the line 157 redirect check.
    • In NavigationRoot's initialState initializer (lines 177-187), skip restoring lastVisitedPath when isOnboardingPath(lastVisitedPath) && !isJoinWorkspaceTaskPath(lastVisitedPath), returning getAdaptedStateFromPath(ROUTES.HOME) instead.
  2. Gate OnboardingGuard and useOnboardingFlowRouter on initial ReconnectApp sync (src/ONYXKEYS.ts, src/libs/actions/App.ts, src/libs/Navigation/guards/, src/hooks/useOnboardingFlow.ts):

    • Track initial ReconnectApp pending state (for example via a new ONYXKEYS.RAM_ONLY_IS_RECONNECTING_APP flag) when AuthScreensInitHandler (src/libs/Navigation/AppNavigator/AuthScreensInitHandler.tsx:229) calls App.reconnectApp. Clear it when reconnectAppPromise settles (src/libs/actions/App.ts:502-511), leaving ONYXKEYS.IS_LOADING_APP untouched.
    • In src/libs/Navigation/guards/index.ts:33-39, 64 and src/libs/Navigation/guards/OnboardingGuard.ts:304-321, treat an active online initial ReconnectApp as loading inside shouldSkipOnboarding (line 308). This stops pre-sync root actions from redirecting HOME into onboarding (OnboardingGuard.ts:339-357).
    • In useOnboardingFlowRouter (src/hooks/useOnboardingFlow.ts:84-86), return early while online initial ReconnectApp is pending so startOnboardingFlow (line 144) waits for fresh membership data.
    • If onboarding was auto-opened before sync (for example while offline) and ReconnectApp lands with isInvitedOrGroupMember === true outside a isJoinWorkspaceTask flow, dismiss it via Navigation.dismissModal(). Mid-flow workspace joins (tests/unit/LinkOpenReportFromDeepLinkTest.ts:249-265) remain unaffected.
  3. Add unit tests:

    • In tests/unit/NavigationRootInitialStateTest.tsx, verify non-task onboarding lastVisitedPath values are not restored on root launch and invited/workspace members opening onboarding initial URLs land on ROUTES.HOME.
    • In tests/unit/Navigation/guards/OnboardingGuard.test.ts, verify OnboardingGuard.evaluate returns {type: 'ALLOW'} while initial ReconnectApp is pending so pre-sync root actions do not redirect into onboarding.
    • Add a useOnboardingFlowRouter unit test verifying startOnboardingFlow waits for initial ReconnectApp and skips onboarding when HAS_NON_PERSONAL_POLICY returns true.

What alternative solutions did you explore? (Optional)

  • Checking isInvitedOrGroupMember only in NavigationRoot's useState initializer: Rejected because NavigationRoot mounts before ReconnectApp finishes, so cached Onyx still holds stale pre-invite values at mount time.
  • Adding SCREENS.ONBOARDING.* to CONST.EXCLUDE_FROM_LAST_VISITED_PATH: Rejected because parseAndLogRoute (src/libs/Navigation/NavigationRoot.tsx:92-97) checks that list before calling updateOnboardingLastVisitedPath(currentPath), which would break step resumption.
  • Setting ONYXKEYS.IS_LOADING_APP = true during ReconnectApp: Rejected because IS_LOADING_APP drives app-wide loading skeletons and would degrade cold-reopen UX for cached sessions.

Contributor: Upwork https://www.upwork.com/freelancers/~013d295f05a578824b | Email: [email protected]

— submitted with Antigravity on the contributor's behalf

HindsightWise avatar Nov 14 '26 14:11 HindsightWise

Proposal

Please re-state the problem that we are trying to solve in this issue.

When a user signs up in OldDot, opens NewDot (which enters the onboarding flow and persists /onboarding/... to Onyx), and is then invited as a member to a Collect workspace in OldDot, reopening staging.new.expensify.com still displays the NewDot onboarding flow instead of landing on the workspace/Home view.

What is the root cause of that problem?

The issue is caused by a combination of cold-start route restoration in src/libs/Navigation/NavigationRoot.tsx, missing redirect guards for users whose shouldSkipOnboarding state becomes true before completing onboarding (isInvitedOrGroupMember / isMigratedUser), and useOnboardingFlowRouter not dismissing an already-mounted ONBOARDING_MODAL_NAVIGATOR when OpenApp updates ONYXKEYS.HAS_NON_PERSONAL_POLICY or ONYXKEYS.NVP_INTRO_SELECTED asynchronously:

  1. Cold-start restoration in NavigationRoot.tsx restores /onboarding/... from lastVisitedPath (and direct URLs) without checking isInvitedOrGroupMember / isMigratedUser: In src/libs/Navigation/NavigationRoot.tsx (lines 93–96), when the user first visits NewDot in Step 3, parseAndLogRoute saves /onboarding/purpose (or /onboarding/work-email) into ONYXKEYS.LAST_VISITED_PATH (lastVisitedPath). When the user is subsequently invited to a workspace in OldDot (Step 4) and reopens NewDot at / (Step 5), NavigationRoot.tsx (lines 153–191) computes initialState:

    • Line 155–159 only checks if ((isOnboardingCompleted || shouldSuppressPromotionalUI) && shouldRedirectCompletedUser) on path (initialUrl), not on lastVisitedPath, and does not include isInvitedOrGroupMember (hasNonPersonalPolicy || wasInvitedToNewDot) or isMigratedUser (tryNewDot?.hasBeenAddedToNudgeMigration).
    • Line 177–187 then checks if (shouldOpenLastVisitedPath(lastVisitedPath) && authenticated) and restores getAdaptedStateFromPath(lastVisitedPath) (/onboarding/...) whenever initialUrl is /! Because initialState is passed directly to <NavigationContainer initialState={initialState}>, it bypasses OnboardingGuard.evaluate.
  2. OnboardingGuard.ts only redirects isOnboardingCompleted and isPromotionalUISuppressed away from onboarding routes: In src/libs/Navigation/guards/OnboardingGuard.ts (lines 275–278), the guard redirects if (onboarding && isOnboardingCompleted && isNavigatingToOnboardingFlow(action) && !isNavigatingToJoinWorkspaceTaskRoute) to ROUTES.HOME. However, for an invited workspace member (isInvitedOrGroupMember = (hasNonPersonalPolicy || wasInvitedToNewDot) ?? false) or migrated user (isMigratedUser), isOnboardingCompleted is still false (hasCompletedGuidedSetupFlow was never set). As a result, lines 275–278 do not trigger, and lines 312–321 (if (shouldSkipOnboarding) { return {type: 'ALLOW'}; }) allow the navigation to /onboarding/... instead of redirecting non-join-workspace onboarding routes to ROUTES.HOME.

  3. Asynchronous OpenApp Onyx sync when ONBOARDING_MODAL_NAVIGATOR is already mounted: When the user opens NewDot in the same browser after being invited in OldDot, ONYXKEYS.HAS_NON_PERSONAL_POLICY is initially false in local IndexedDB until OpenApp resolves from the server. Before OpenApp finishes (or from lastVisitedPath restoration on mount), ONBOARDING_MODAL_NAVIGATOR is already mounted at the top of RootStack. Once OpenApp sets hasNonPersonalPolicy = true, useOnboardingFlowRouter in src/hooks/useOnboardingFlow.ts (lines 115–119) simply executes:

    const isMigratedUser = hasBeenAddedToNudgeMigration ?? false;
    const isInvitedOrGroupMember = (hasNonPersonalPolicy || wasInvitedToNewDot) ?? false;
    if (isMigratedUser || isInvitedOrGroupMember || shouldSuppressPromotionalUI) {
        return;
    }
    

    Returning early prevents startOnboardingFlow from being called again, but leaves the already-mounted ONBOARDING_MODAL_NAVIGATOR on screen!

What changes do you think we should make in order to solve the problem?

  1. src/libs/Navigation/NavigationRoot.tsx:

    • Read hasNonPersonalPolicy (ONYXKEYS.HAS_NON_PERSONAL_POLICY), wasInvitedToNewDot (ONYXKEYS.NVP_INTRO_SELECTED with wasInvitedToNewDotSelector), and tryNewDot (ONYXKEYS.NVP_TRY_NEW_DOT with tryNewDotOnyxSelector), and compute:
      const isMigratedUser = tryNewDot?.hasBeenAddedToNudgeMigration ?? false;
      const isInvitedOrGroupMember = (hasNonPersonalPolicy || wasInvitedToNewDot) ?? false;
      const shouldBypassOnboarding = isOnboardingCompleted || shouldSuppressPromotionalUI || isMigratedUser || isInvitedOrGroupMember;
      
    • In the initialState initializer (lines 155–187):
      • Use shouldBypassOnboarding instead of isOnboardingCompleted || shouldSuppressPromotionalUI when checking shouldRedirectCompletedUser (!!path && isOnboardingPath(path) && !isJoinWorkspaceTaskPath(path)).
      • Before restoring lastVisitedPath in if (shouldOpenLastVisitedPath(lastVisitedPath) && authenticated), check if shouldBypassOnboarding && isOnboardingPath(lastVisitedPath) && !isJoinWorkspaceTaskPath(lastVisitedPath); if so, skip restoring the stale onboarding lastVisitedPath (or return getAdaptedStateFromPath(ROUTES.HOME)).
  2. src/libs/Navigation/guards/OnboardingGuard.ts:

    • In OnboardingGuard.evaluate (lines 275–278), extend the redirect condition so invited workspace members and migrated users who have not completed guided setup are also redirected to ROUTES.HOME when navigating to non-join-workspace onboarding routes:
      if (((onboarding && isOnboardingCompleted) || isInvitedOrGroupMember || isMigratedUser) && isNavigatingToOnboardingFlow(action) && !isNavigatingToJoinWorkspaceTaskRoute) {
          Log.info('[OnboardingGuard] Redirecting user away from onboarding route to home');
          return {type: 'REDIRECT', route: ROUTES.HOME};
      }
      
  3. src/hooks/useOnboardingFlow.ts:

    • In useOnboardingFlowRouter (lines 115–119), when isMigratedUser || isInvitedOrGroupMember || shouldSuppressPromotionalUI is true, check if the root stack currently has NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR focused (and not on a join-workspace task route). If so, dismiss the onboarding modal (Navigation.dismissModal()) and clear the stale onboarding lastVisitedPath so that when OpenApp finishes loading hasNonPersonalPolicy = true after mount, the onboarding modal is immediately closed:
      if (isMigratedUser || isInvitedOrGroupMember || shouldSuppressPromotionalUI) {
          if (Navigation.isOnboardingFlow() && !isJoinWorkspaceTaskPath(Navigation.getActiveRoute())) {
              Navigation.isNavigationReady().then(() => {
                  Navigation.dismissModal();
              });
          }
          return;
      }
      

What alternative solutions did you explore? (Optional)

We considered only preventing lastVisitedPath from being restored when isOnboardingPath(lastVisitedPath) is true in NavigationRoot.tsx, but that would either break legitimate onboarding step resumption for uninvited users or fail when OpenApp updates ONYXKEYS.HAS_NON_PERSONAL_POLICY asynchronously after the initial render. Handling both cold-start restoration/guarding (NavigationRoot.tsx + OnboardingGuard.ts) and reactive dismissal upon OpenApp sync (useOnboardingFlow.ts) covers both cached and fresh sessions cleanly.

cocvn157 avatar Nov 14 '26 14:11 cocvn157

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~014898525b9c53fc32

Proposal

Please re-state the problem that we are trying to solve in this issue.

When a user signs up on OldDot, opens NewDot (which enters onboarding and persists an onboarding route to Onyx), closes the tab without finishing onboarding, and is then invited to a Collect workspace as a member in OldDot, reopening NewDot still mounts and displays the onboarding modal instead of bypassing onboarding and navigating directly to Home/workspace.

What is the root cause of that problem?

  1. OnboardingGuard fails to redirect exempt invited members away from restored onboarding routes (src/libs/Navigation/guards/OnboardingGuard.ts:275-278 vs 319-321): When navigating to an onboarding route (isNavigatingToOnboardingFlow(action) is true), line 275 only issues a redirect to ROUTES.HOME if isOnboardingCompleted is true:

    if (onboarding && isOnboardingCompleted && isNavigatingToOnboardingFlow(action) && !isNavigatingToJoinWorkspaceTaskRoute) {
        return {type: 'REDIRECT', route: ROUTES.HOME};
    }
    

    For an invited workspace member, isOnboardingCompleted is false, but hasNonPersonalPolicy or wasInvitedToNewDot is true (making isInvitedOrGroupMember = true). Because line 275 ignores isInvitedOrGroupMember, the guard falls through to line 319:

    if (shouldSkipOnboarding) {
        return {type: 'ALLOW'};
    }
    

    Since shouldSkipOnboarding includes isInvitedOrGroupMember, the guard returns {type: 'ALLOW'}, authorizing the restored onboarding route to mount!

  2. Stale onboarding route restored from lastVisitedPath on cold start (src/libs/Navigation/NavigationRoot.tsx:177-186 & 94-96): When the user initially opened NewDot, NavigationRoot saved the onboarding route to lastVisitedPath and onboardingLastVisitedPath. On cold reopen, NavigationRoot reads lastVisitedPath and generates the initial navigation state targeting that saved onboarding route. Because OnboardingGuard returns ALLOW, the app mounts the abandoned onboarding screen.

What changes do you think we should make in order to solve the problem?

  1. Update OnboardingGuard.ts:275-278 to redirect all exempt/skip-onboarding users away from onboarding routes: Update the redirect check to evaluate whether the user should skip onboarding (e.g. isInvitedOrGroupMember, isMigratedUser, or isOnboardingCompleted):

    const isExemptFromOnboarding = isOnboardingCompleted || isInvitedOrGroupMember || isMigratedUser;
    if (isExemptFromOnboarding && isNavigatingToOnboardingFlow(action) && !isNavigatingToJoinWorkspaceTaskRoute) {
        Log.info('[OnboardingGuard] Redirecting exempt/completed user away from onboarding route to home');
        return {type: 'REDIRECT', route: ROUTES.HOME};
    }
    

    This guarantees that even if a stale onboarding route is restored from cache or accessed via deep link, OnboardingGuard intercepts it and redirects the invited member directly to ROUTES.HOME.

  2. Clean up stale onboarding paths when non-personal policies are detected: When ONYXKEYS.HAS_NON_PERSONAL_POLICY or wasInvitedToNewDot evaluates to true, clear or overwrite ONYXKEYS.ONBOARDING_LAST_VISITED_PATH and reset lastVisitedPath if it points to an onboarding subroute, preventing unnecessary redirect thrashing on initial load.

  3. Automated tests:

    • In tests/unit/OnboardingGuardTest.ts: Add test cases verifying that when hasNonPersonalPolicy: true or wasInvitedToNewDot: true (with isOnboardingCompleted: false), navigating to any onboarding route (/onboarding/purpose, /onboarding/workspaces, etc.) returns {type: 'REDIRECT', route: ROUTES.HOME}.
    • In tests/unit/NavigationRootTest.tsx: Test that a cold open with a stale onboarding lastVisitedPath for an invited workspace member lands on ROUTES.HOME.

What alternative solutions did you explore? (Optional)

  • Only clearing lastVisitedPath in NavigationRoot: Rejected because if an invited member clicks a stale browser bookmark or external deeplink to /onboarding/..., OnboardingGuard would still return ALLOW and display onboarding. Fixing the guard at the navigation boundary protects both cold starts and direct link navigation.

RajGahoi avatar Nov 14 '26 16:11 RajGahoi

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 14 '26 16:11 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

When a user signs up in OldDot, opens NewDot without finishing onboarding, closes the window, is invited as a member to a Collect workspace in OldDot, and then reopens NewDot (staging.new.expensify.com), the onboarding modal is still displayed instead of landing directly in the app.

What is the root cause of that problem?

Two gaps combine when an account with an unfinished onboarding session is invited to a workspace while NewDot is closed:

  1. Startup initialState restores saved onboarding routes without checking workspace-member or invitation exemptions:

    • In Step 3, parseAndLogRoute (src/libs/Navigation/NavigationRoot.tsx:92-96) saves the active /onboarding/... path to ONYXKEYS.LAST_VISITED_PATH and ONYXKEYS.ONBOARDING_LAST_VISITED_PATH.
    • On Step 5 reopen at /, NavigationRoot (src/libs/Navigation/NavigationRoot.tsx:153-187) only checks isOnboardingCompleted || shouldSuppressPromotionalUI against initialUrl (lines 155-159), omitting isInvitedOrGroupMember (hasNonPersonalPolicy || wasInvitedToNewDot) and isMigratedUser, and then restores getAdaptedStateFromPath(lastVisitedPath) (lines 177-186). Because initialState goes straight to NavigationContainer, it bypasses OnboardingGuard and mounts ONBOARDING_MODAL_NAVIGATOR immediately.
  2. Initial ReconnectApp sync updates membership asynchronously without dismissing the startup-restored onboarding modal:

    • Because the workspace invitation in Step 4 occurred while NewDot was closed, cached IndexedDB still holds HAS_NON_PERSONAL_POLICY as false/undefined when NavigationRoot mounts (before AuthScreensInitHandler.tsx:229 dispatches App.reconnectApp, which sets ONYXKEYS.IS_LOADING_REPORT_DATA to true until sync finishes rather than ONYXKEYS.IS_LOADING_APP).
    • Once ReconnectApp resolves and sets ONYXKEYS.HAS_NON_PERSONAL_POLICY to true, useOnboardingFlowRouter (src/hooks/useOnboardingFlow.ts:115-119) sees isInvitedOrGroupMember === true and returns early. That early return only avoids starting a new flow—it leaves the startup-mounted ONBOARDING_MODAL_NAVIGATOR stuck on screen.

What changes do you think we should make in order to solve the problem?

  1. Prevent NavigationRoot from restoring or opening non-task onboarding routes for exempt users (src/libs/Navigation/NavigationRoot.tsx):

    • Read ONYXKEYS.HAS_NON_PERSONAL_POLICY, ONYXKEYS.NVP_INTRO_SELECTED (wasInvitedToNewDotSelector), and ONYXKEYS.NVP_TRY_NEW_DOT (tryNewDotOnyxSelector) in NavigationRoot to compute isInvitedOrGroupMember and isMigratedUser alongside isOnboardingCompleted and shouldSuppressPromotionalUI.
    • In the initialState initializer (lines 155-187), return getAdaptedStateFromPath(ROUTES.HOME) both when initialUrl is a non-task onboarding path and when lastVisitedPath is a non-task onboarding path (isOnboardingPath(lastVisitedPath) && !isJoinWorkspaceTaskPath(lastVisitedPath)) for these exempt users.
  2. Wait for initial ReconnectApp report/policy sync and dismiss only startup-restored onboarding modals in useOnboardingFlowRouter (src/hooks/useOnboardingFlow.ts):

    • Read ONYXKEYS.IS_LOADING_REPORT_DATA and useNetwork().isOffline, and track a hasEvaluatedStartupSyncRef ref so startup exemption is evaluated once initial sync settles (!isOffline && isLoadingReportData waits for the in-flight OpenApp/ReconnectApp started in AuthScreensInitHandler.tsx:226-229 before auto-starting or dismissing onboarding).
    • On that initial post-sync check, if isMigratedUser || isInvitedOrGroupMember || shouldSuppressPromotionalUI is true and Navigation.isOnboardingFlow() is mounted on a non-task route (!isJoinWorkspaceTaskPath(Navigation.getActiveRoute())), clear ONYXKEYS.ONBOARDING_LAST_VISITED_PATH via updateOnboardingLastVisitedPath('') and call Navigation.isNavigationReady().then(() => Navigation.dismissModal()) to reveal TAB_NAVIGATOR (HOME) underneath (which also updates LAST_VISITED_PATH to /).
    • Because this dismissal runs only on the initial startup sync check (hasEvaluatedStartupSyncRef), any workspace join or account merge performed later during an active onboarding session (BaseOnboardingWorkspaces, BaseOnboardingWorkEmailValidation, and LinkOpenReportFromDeepLinkTest.ts:249-265) keeps onboarding open until completeOnboarding finishes.
  3. Redirect external warm deep links into onboarding for exempt users in OnboardingGuard (src/libs/Navigation/guards/OnboardingGuard.ts):

    • When ONBOARDING_MODAL_NAVIGATOR is not already focused (!isOnboardingFocused) and isInvitedOrGroupMember || isMigratedUser is true, return {type: 'REDIRECT', route: ROUTES.HOME} for isNavigatingToOnboardingFlow(action) && !isNavigatingToJoinWorkspaceTaskRoute. Scoping this to !isOnboardingFocused blocks warm /onboarding/... links without interfering with internal step transitions (such as ONBOARDING_WORKSPACES to ONBOARDING_PERSONAL_DETAILS) inside an active flow.
  4. Unit tests:

    • Extend tests/unit/NavigationRootInitialStateTest.tsx to verify that invited/workspace members (HAS_NON_PERSONAL_POLICY: true or NVP_INTRO_SELECTED.inviteType) with incomplete onboarding land on ROUTES.HOME when lastVisitedPath or initialUrl is /onboarding/purpose, while plain uninvited users still restore their saved onboarding step.
    • Add unit tests in tests/unit/Navigation/guards/OnboardingGuard.test.ts and for useOnboardingFlowRouter covering post-ReconnectApp startup dismissal vs. preserving an active mid-session workspace join.

What alternative solutions did you explore? (Optional)

  • Checking isInvitedOrGroupMember only in NavigationRoot's useState initializer: Insufficient on its own because Step 4 invites the user while NewDot is closed, so cached Onyx still holds pre-invite state until ReconnectApp resolves after mount.
  • Unconditionally redirecting isInvitedOrGroupMember in OnboardingGuard or dismissing onboarding on every HAS_NON_PERSONAL_POLICY change: Breaks in-session workspace joins (BaseOnboardingWorkspaces.tsx:169-174, 211) and account merges (BaseOnboardingWorkEmailValidation.tsx:134-143) where HAS_NON_PERSONAL_POLICY becomes true before ONBOARDING_PERSONAL_DETAILS / completeOnboarding runs.
  • Stopping parseAndLogRoute from saving /onboarding/... to LAST_VISITED_PATH: Degrades cold-start step resumption for normal uninvited users by mounting HOME first before useOnboardingFlowRouter resets back into onboarding.

chaos666888 avatar Nov 15 '26 02:11 chaos666888

📣 @chaos666888! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 15 '26 02:11 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

When a user signs up on OldDot (Manage expenses for 1-9 employees), opens NewDot without finishing the onboarding modal (so an /onboarding/... path is saved in lastVisitedPath), and is then invited as a member to a Collect workspace in OldDot, reopening NewDot (staging.new.expensify.com) still displays the onboarding modal instead of taking the invited member to Home.

What is the root cause of that problem?

  1. Cold-start initialState and lastVisitedPath restoration in src/libs/Navigation/NavigationRoot.tsx bypasses isInvitedOrGroupMember:
    • While useOnboardingFlow.ts and OnboardingGuard.ts define isInvitedOrGroupMember = hasNonPersonalPolicy || wasInvitedToNewDotSelector(introSelected) to skip onboarding for workspace members, NavigationRoot.tsx (lines 153-190) only checks isOnboardingCompleted || shouldSuppressPromotionalUI when computing initialState.
    • When the returning user opens NewDot at the root URL (/), NavigationRoot restores lastVisitedPath (/onboarding/...) directly via getAdaptedStateFromPath(lastVisitedPath). Because computing initialState bypasses OnboardingGuard, ONBOARDING_MODAL_NAVIGATOR mounts directly on startup.
  2. OnboardingGuard.ts does not actively redirect isInvitedOrGroupMember away from onboarding routes (src/libs/Navigation/guards/OnboardingGuard.ts:273-301):
    • In OnboardingGuard.evaluate, isInvitedOrGroupMember is included in shouldSkipOnboarding (which returns {type: 'ALLOW'}), but is omitted from the active redirect check (if ((isOnboardingCompleted || isSingleNewDotEntry || isTestBuild || shouldSuppressPromotionalUI) && ...) return {type: 'REDIRECT', route: ROUTES.HOME}). Thus, when an invited workspace member's navigation state targets an onboarding route (or when hasNonPersonalPolicy hydrates via Onyx), OnboardingGuard allows them to remain on the onboarding modal instead of redirecting to ROUTES.HOME.

What changes do you think we should make in order to solve the problem?

  1. Include isInvitedOrGroupMember in NavigationRoot.tsx startup route resolution (src/libs/Navigation/NavigationRoot.tsx):
    • Subscribe to ONYXKEYS.HAS_NON_PERSONAL_POLICY and ONYXKEYS.NVP_INTRO_SELECTED (using wasInvitedToNewDotSelector) to compute isInvitedOrGroupMember.
    • In the initialState calculation (line 157) and the lastVisitedPath onboarding restoration guard (line 183), treat isInvitedOrGroupMember alongside isOnboardingCompleted || shouldSuppressPromotionalUI so stale onboarding lastVisitedPath entries resolve to getAdaptedStateFromPath(ROUTES.HOME) (unless navigating to a join-workspace task route).
  2. Redirect isInvitedOrGroupMember away from onboarding routes in src/libs/Navigation/guards/OnboardingGuard.ts:
    • In OnboardingGuard.evaluate (lines 285-301), include isInvitedOrGroupMember in the redirect condition so any navigation/replace into onboarding routes (other than join-workspace task routes) returns {type: 'REDIRECT', route: ROUTES.HOME}.
    • Dismiss the mounted onboarding modal if hasNonPersonalPolicy hydrates after initial mount while the user is on an onboarding route.
  3. Add unit tests:
    • Add unit tests in tests/unit/NavigationRootInitialStateTest.tsx and tests/unit/Navigation/guards/OnboardingGuard.test.ts verifying that an invited member (HAS_NON_PERSONAL_POLICY: true) with an uncompleted onboarding state and an /onboarding/... lastVisitedPath lands on ROUTES.HOME.

What alternative solutions did you explore? (Optional)

  • Clearing LAST_VISITED_PATH in Onyx when policy data changes: Rejected because handling isInvitedOrGroupMember declaratively in NavigationRoot and OnboardingGuard matches how isOnboardingCompleted and shouldSuppressPromotionalUI are already handled without mutating persisted route history.

U-ITACHII avatar Nov 15 '26 10:11 U-ITACHII

Proposal

Proposal

Please re-state the problem that we are trying to solve in this issue.

When a user signs up on OldDot (Manage expenses for 1-9 employees), opens NewDot without completing the onboarding modal (which saves an /onboarding/... route to lastVisitedPath), closes the window, is invited as a member to a Collect workspace in OldDot, and then reopens NewDot at staging.new.expensify.com, the onboarding modal is still displayed instead of landing in the app at Home.

What is the root cause of that problem?

There are three compounding causes that keep the invited workspace member trapped in onboarding:

  1. Unconditional lastVisitedPath restoration of onboarding routes in src/libs/Navigation/NavigationRoot.tsx:

    • During step 3, parseAndLogRoute saves the active onboarding path (/onboarding/...) to ONYXKEYS.LAST_VISITED_PATH and ONYXKEYS.ONBOARDING_LAST_VISITED_PATH.
    • On cold reopen at step 5 (https://staging.new.expensify.com/), initialUrl is the root URL (/).
    • In NavigationRoot.tsx:155-159, shouldRedirectCompletedUser is false (because path is /, not an onboarding URL), and the redirect condition only checks isOnboardingCompleted, completely omitting isInvitedOrGroupMember.
    • Execution falls through to line 177:
      if (shouldOpenLastVisitedPath(lastVisitedPath) && authenticated) {
          if (!isSpecificDeepLink) {
              return getAdaptedStateFromPath(lastVisitedPath);
          }
      }
      
      lastVisitedPath (/onboarding/purpose) is unconditionally restored into initialState via getAdaptedStateFromPath(lastVisitedPath) without verifying whether lastVisitedPath is an onboarding route or whether the user is eligible for onboarding.
    • Because computing initialState skips navigation guards, React Navigation immediately mounts ONBOARDING_MODAL_NAVIGATOR on startup.
  2. Missing redirect for isInvitedOrGroupMember in src/libs/Navigation/guards/OnboardingGuard.ts:

    • In OnboardingGuard.evaluate:
      if (isOnboardingCompleted && isNavigatingToOnboardingFlow(action) && !isNavigatingToJoinWorkspaceTaskRoute) {
          return {type: 'REDIRECT', route: ROUTES.HOME};
      }
      
      Completed users are actively redirected to ROUTES.HOME. However, isInvitedOrGroupMember is omitted from this redirect check. Instead, isInvitedOrGroupMember is only included in shouldSkipOnboarding (lines 280–298), which returns {type: 'ALLOW'}. Once mounted, OnboardingGuard allows the user to remain on the onboarding screen rather than redirecting them to ROUTES.HOME.
  3. No dismissal when HAS_NON_PERSONAL_POLICY hydrates asynchronously in src/hooks/useOnboardingFlow.ts:

    • When the user was invited while NewDot was closed, cached Onyx may still reflect pre-invite state until ReconnectApp / OpenApp returns from the backend.
    • Once ReconnectApp resolves and hasNonPersonalPolicy becomes true, useOnboardingFlow.ts:110 merely returns early (if (isInvitedOrGroupMember) return;), which prevents starting onboarding but never dismisses the onboarding modal that was already mounted by initialState.

What changes do you think we should make in order to solve the problem?

  1. Guard lastVisitedPath restoration and initialState in src/libs/Navigation/NavigationRoot.tsx:

    • Subscribe to ONYXKEYS.HAS_NON_PERSONAL_POLICY and ONYXKEYS.NVP_INTRO_SELECTED:
      const [hasNonPersonalPolicy] = useOnyx(ONYXKEYS.HAS_NON_PERSONAL_POLICY);
      const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
      const isInvitedOrGroupMember = (hasNonPersonalPolicy || wasInvitedToNewDotSelector(introSelected)) ?? false;
      
    • In initialState (line 157), include isInvitedOrGroupMember:
      const shouldRedirectOnboardingUser = !!path && isOnboardingPath(path) && !isJoinWorkspaceTaskPath(path);
      if ((isOnboardingCompleted || shouldSuppressPromotionalUI || isInvitedOrGroupMember) && shouldRedirectOnboardingUser) {
          return getAdaptedStateFromPath(ROUTES.HOME);
      }
      
    • In the lastVisitedPath restoration check (line 177), check if lastVisitedPath is an onboarding route. If isOnboardingPath(lastVisitedPath) && !isJoinWorkspaceTaskPath(lastVisitedPath) and isOnboardingCompleted || shouldSuppressPromotionalUI || isInvitedOrGroupMember, do not restore the stale onboarding path; resolve to ROUTES.HOME instead:
      if (shouldOpenLastVisitedPath(lastVisitedPath) && authenticated) {
          const isRootPath = !path || path === '' || path === '/';
          const isSpecificDeepLink = path && !isRootPath;
      
          if (!isSpecificDeepLink) {
              if (isOnboardingPath(lastVisitedPath) && !isJoinWorkspaceTaskPath(lastVisitedPath)) {
                  if (isOnboardingCompleted || shouldSuppressPromotionalUI || isInvitedOrGroupMember) {
                      return getAdaptedStateFromPath(ROUTES.HOME);
                  }
              }
      
              Log.info('Restoring last visited path on app startup', false, {lastVisitedPath, initialUrl, path});
              return getAdaptedStateFromPath(lastVisitedPath);
          }
      }
      
  2. Redirect invited members away from onboarding in src/libs/Navigation/guards/OnboardingGuard.ts:

    • Update the redirect check to include isInvitedOrGroupMember:
      if ((isOnboardingCompleted || isInvitedOrGroupMember) && isNavigatingToOnboardingFlow(action) && !isNavigatingToJoinWorkspaceTaskRoute) {
          Log.info('[OnboardingGuard] Redirecting invited or completed user away from onboarding route to home');
          return {type: 'REDIRECT', route: ROUTES.HOME};
      }
      
  3. Dismiss mounted onboarding modal on hydration in src/hooks/useOnboardingFlow.ts:

    • When isInvitedOrGroupMember becomes true after ReconnectApp hydrates Onyx:
      if (isMigratedUser || isInvitedOrGroupMember || shouldSuppressPromotionalUI) {
          if (isInvitedOrGroupMember) {
              const activeRoute = Navigation.getActiveRoute();
              if (isOnboardingPath(activeRoute) && !isJoinWorkspaceTaskPath(activeRoute)) {
                  Navigation.navigate(ROUTES.HOME);
              }
          }
          return;
      }
      
    • This guarantees that even if a cold start mounts before ReconnectApp returns policy membership, the modal dismisses automatically as soon as the invite data arrives.
  4. Add automated tests:

    • In tests/unit/NavigationRootInitialStateTest.tsx:
      • Test that an invited member (HAS_NON_PERSONAL_POLICY: true) with an incomplete onboarding state and an /onboarding/... lastVisitedPath resolves its initial state to ROUTES.HOME on root URL cold start.
    • In tests/unit/Navigation/guards/OnboardingGuard.test.ts:
      • Test that OnboardingGuard returns {type: 'REDIRECT', route: ROUTES.HOME} when an invited workspace member attempts to navigate to an onboarding route (non-join-task).

What alternative solutions did you explore? (Optional)

  • Clearing LAST_VISITED_PATH or ONBOARDING_LAST_VISITED_PATH in Onyx when policy data changes: Discarded because LAST_VISITED_PATH is a navigation history cursor; mutating stored route history during background policy synchronization introduces race conditions across tabs and sessions.
  • Relying solely on NavigationRoot.tsx: Discarded because when the invite is sent while NewDot is closed, cached client storage lacks the new workspace until ReconnectApp completes over the network; combining NavigationRoot, OnboardingGuard, and useOnboardingFlow ensures instant and seamless dismissal across both cached and freshly hydrated states.

Test Plan

  1. Sign up a new account on OldDot selecting "Manage expenses for 1-9 employees".
  2. Open NewDot; observe that the onboarding modal is displayed. Close the browser tab without completing onboarding.
  3. From a separate admin account on OldDot, invite the new account as a member to a Collect workspace.
  4. As the invited account, reopen staging.new.expensify.com:
    • Verify that the app opens directly to Home (/).
    • Verify that the onboarding modal is NOT displayed.
  5. Manually enter an onboarding URL (e.g. staging.new.expensify.com/onboarding/purpose) in the browser address bar:
    • Verify that the user is immediately redirected to Home (/).
  6. Uninvited new user regression check:
    • Sign up a fresh account without any workspace invite.
    • Leave onboarding, close the tab, and reopen staging.new.expensify.com.
    • Verify that onboarding correctly resumes where the user left off.

Contributor details

Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0105126232377c4c5c

ayolyn avatar Nov 15 '26 22:11 ayolyn

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 15 '26 22:11 melvin-bot[bot]

Contributor details:

  • Expensify account email: [email protected]
  • Upwork profile: https://www.upwork.com/freelancers/~013b564a690d9bcdab

Proposal

Problem

A user signs up via OldDot, opens NewDot without finishing onboarding, and closes the window. The user is then invited to a Collect workspace as a member. On reopening staging.new.expensify.com, the onboarding modal is shown instead of the app. An invited workspace member should land in the app (Home), with no onboarding modal.

Root cause - and why the fix has to be in three places

NavigationRoot.tsx saves every /onboarding/... path to lastVisitedPath and, on a cold open at the root URL, restores it with no exemption check. OnboardingGuard.ts then turns the invited-member status into ALLOW, and useOnboardingFlow.ts only stops STARTING onboarding - nothing dismisses one already on screen.

There is one timing fact that decides where the fix can live, and it is easy to miss: HAS_NON_PERSONAL_POLICY is false in local storage until OpenApp / ReconnectApp resolves from the server, and NavigationRoot mounts BEFORE that sync (Expensify.tsx waits only for the initial URL, not for the policy sync). setUpPoliciesAndNavigate only navigates when the URL carries an exitTo param, so in this repro no navigation action is dispatched after the policy sync. Consequences:

  • An initialState fix alone only works when the flag is already persisted (a second launch). It does NOT fix the repro as written: the flag arrives after mount, and the useState initializer never re-runs.
  • A guard fix alone cannot work either: OnboardingGuard only evaluates dispatched navigation actions, and the repro dispatches none after mount.
  • The repro can only be fixed by a post-mount reaction when the exemption hydrates - and that reaction must be scoped to startup, because useOnboardingFlowRouter's effect re-runs when the invite flag changes. An unscoped dismissal would also fire when a user joins a workspace MID-FLOW during active onboarding, which is intentional behaviour protected by LinkOpenReportFromDeepLinkTest ("does not bypass an open onboarding flow for an invited user", "keeps an open onboarding flow in charge even after the user joins a workspace").

Changes

  1. src/libs/Navigation/NavigationRoot.tsx - initial state (covers flags already persisted). Subscribe to HAS_NON_PERSONAL_POLICY and NVP_INTRO_SELECTED (wasInvitedToNewDot), plus tryNewDot for migration, and compute isInvitedOrGroupMember = hasNonPersonalPolicy || wasInvitedToNewDot and shouldBypassOnboarding = isOnboardingCompleted || shouldSuppressPromotionalUI || isMigratedUser || isInvitedOrGroupMember. Use it in both places: the redirect for a direct launch into an onboarding URL, and the lastVisitedPath restoration branch - when the user is exempt and the stored path is an onboarding route (and not a join-workspace-task route), restore ROUTES.HOME instead. The isJoinWorkspaceTaskPath exemption and the migrated-user-welcome branch are untouched.

  2. src/libs/Navigation/guards/OnboardingGuard.ts - deep-link defence. Extend the redirect so exempt users are also redirected to HOME when an action targets a non-task onboarding route. Stated honestly: this does not fix the repro on its own (the guard only evaluates dispatched actions), it protects deep links and programmatic navigations into onboarding.

  3. src/hooks/useOnboardingFlow.ts - one-shot startup dismissal (the missing piece). In useOnboardingFlowRouter, add a hasEvaluatedStartupDismissalRef that is set once isLoadingApp becomes false - the first moment the policy flag is trustworthy after the initial sync. If, at that moment, the user is exempt (isMigratedUser || isInvitedOrGroupMember || shouldSuppressPromotionalUI), the focused route is an onboarding route, and it is not a join-workspace-task route, dismiss the modal with Navigation.dismissModal() and clear ONBOARDING_LAST_VISITED_PATH: Navigation.isNavigationReady().then(() => { Navigation.dismissModal(); updateOnboardingLastVisitedPath(''); }).

    • Gated on isLoadingApp, not on report-data loading: the policy flag arrives with the initial OpenApp / ReconnectApp load, which is what isLoadingApp tracks.
    • One-shot by design: the decision is made once, at startup. A user who gets invited mid-flow - after the ref is spent - keeps their onboarding, exactly as the LinkOpenReportFromDeepLinkTest cases require.
    • dismissModal() (dispatches DISMISS_MODAL), not Navigation.navigate(ROUTES.HOME): the guard's ACTIONS_THAT_CAN_LEAVE_ONBOARDING are NAVIGATE / PUSH / REPLACE / POP_TO, and shouldPreventReset covers RESET / GO_BACK - DISMISS_MODAL is in neither set, so the guard cannot block it, and it deterministically removes the mounted modal to reveal TAB_NAVIGATOR (HOME). Whether a NAVIGATE from inside the modal navigator actually dismisses the mounted modal is uncertain.
    • The stale ONBOARDING_LAST_VISITED_PATH is cleared so the step is not offered as a resume point later; LAST_VISITED_PATH self-heals on the next navigation, and the next cold start is covered by step 1 since the flag is persisted by then.

Not changed: persisting onboarding routes in parseAndLogRoute (changing that would alter resume behaviour for ALL users and is not needed once steps 1 and 3 exist); no new Onyx key is added (isLoadingApp is the existing signal); the join-workspace-task routes, the 2FA-setup flow and hybrid-app single-entry flows are untouched; the existing early return in useOnboardingFlowRouter (which only stops STARTING onboarding) is kept.

Tests

  • tests/unit/NavigationRootInitialStateTest.tsx: invited member (HAS_NON_PERSONAL_POLICY: true), onboarding incomplete, lastVisitedPath = /onboarding/purpose, root URL, authenticated - initial state is HOME. Same with introSelected.inviteType set. Control: a plain new user still restores the onboarding route.
  • tests/unit/Navigation/guards/OnboardingGuard.test.ts: an invited member navigating to /onboarding/purpose (non-task) is redirected to HOME; a join-workspace-task route is not redirected.
  • tests/unit/LinkOpenReportFromDeepLinkTest.ts: no change - must keep passing; the two cases ("does not bypass an open onboarding flow for an invited user", "keeps an open onboarding flow in charge even after the user joins a workspace") are the guard rails for the one-shot scoping in step 3.
  • If a harness exists for useOnboardingFlowRouter: the startup dismissal fires once when the flag flips post-mount, and does NOT fire when the flag flips mid-flow after the startup evaluation. Otherwise this is covered by the NavigationRoot + guard tests plus manual QA of the exact repro steps.

Alternatives considered

  • Initial state only. Rejected: it does not fix the repro as written, because the policy flag is not yet true when NavigationRoot mounts.
  • Guard only. Rejected: the guard never evaluates in the repro flow, because no navigation action is dispatched after the policy sync.
  • Unscoped dismissal when the flag flips. Rejected: it would dismiss onboarding mid-flow when a user joins a workspace during active onboarding, breaking the intentional behaviour in LinkOpenReportFromDeepLinkTest.
  • Stop persisting onboarding routes in LAST_VISITED_PATH. Rejected: it changes resume behaviour for every user and is unnecessary once the initial-state fix and the one-shot dismissal exist.
  • Wait for report-data loading before deciding. Rejected: the policy flag arrives with the initial app load (isLoadingApp); report-data loading is irrelevant here and adds a failure mode if it never settles as expected.

dankezo avatar Nov 16 '26 06:11 dankezo

📣 @dankezo! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 16 '26 06:11 melvin-bot[bot]

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~013b564a690d9bcdab

dankezo avatar Nov 16 '26 06:11 dankezo

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 16 '26 06:11 melvin-bot[bot]