Skip to content

[$250] Account - System back button on 2FA success RHP navigates to Account > Security #105693

Open

Description

@applause-bot

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.28-4
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #102482
Email or phone of affected tester (no customers): biruknew45+46cb@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Web, android
App Component: User Settings

Action Performed:

Preconditions:
Account A owns a workspace that requires 2FA (e.g. Xero connected). Account B already finished onboarding and has 2FA disabled.
As Account A, invite Account B to the workspace as an Admin.

  1. Go to staging.new.expensify.com
  2. Log in as Account B
  3. Click "Enable two-factor authentication"
  4. Complete setup by copying codes and entering the 6-digit code
  5. Press the system back button on the success page

Expected Result:

System back button on 2FA success RHP should lead to Home

Actual Result:

System back button on 2FA success RHP leads to Account > Security instead of Home.
The same happens on web: clicking outside the RHP and browser back button

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome Safari

Screenshots/Videos

Bug7303063_1793654842134.1.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Chandana Kiran
Bug ID: 7303063

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

Activity

  1. added
    Daily
    Bug
    on Nov 2, 2026
  2. applause-bot commented on Nov 2, 2026

    @applause-bot
    Author

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

  3. MelvinBot commented on Nov 2, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    Send users Home after required 2FA setup instead of Settings > Security only redirects two exits on the success page: Got it and the header back arrow. Both call sendForcedSetupUserHome() in DynamicSuccessPage.tsx:90-127.

    Three other exits skip that code. Each one pops the whole RHP. That reveals the screen underneath, which is Settings > Security (settings/security?forceSetup=true):

    • Android back button: goBack reaches only the header arrow. Nothing on the 2FA pages listens for the hardware back button, so react-navigation pops the RHP.
    • Clicking outside the RHP: handleOverlayPress calls navigation.goBack() on the root stack (RightModalNavigator.tsx:250-268). The 2FA beforeRemove listener there only clears 2FA data (lines 327-334).
    • Browser back: the previous history entry is settings/security?forceSetup=true, so popstate goes back to it.

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

    In DynamicSuccessPage, intercept every way of removing the screen during a forced setup, not just the button handlers:

    1. Add a usePreventRemove guard that is on when isForcedSetupFlow || shouldReturnToOnboardingAfter2FA.
    2. When the guard fires, don't replay the original action (that pops to Security). Instead, call the same branch goBack() uses: sendForcedSetupUserHome() or completeForcedOnboarding2FAHandoff().
    3. Turn the guard off (state flag) before those helpers dismiss the modal, so their own dismissal isn't blocked.
    4. Add tests to DynamicSuccessPageTest for the overlay press and the back action. Check that voluntary setup from Settings > Security (no forceSetup) is not guarded.

    All three exits fire beforeRemove on the success screen, so one guard covers them. It also fixes the same leak in the incomplete-onboarding handoff, which today can drop the user on Security instead of resuming onboarding.

    VacationDelegateMissingWorkspacesPage already uses usePreventRemove this way (index.tsx:95).

    What alternative solutions did you explore? (Optional)

    • useAndroidBackButtonHandler calling goBack(): fixes Android only. The overlay click and browser back stay broken.
    • Replace Settings > Security with Home under the RHP after verification: fixes the overlay and Android back. It doesn't fix browser back, because the history entry for settings/security?forceSetup=true stays.
    Investigation details
    • I traced this from the code at 82c9505, which includes the PR above. I didn't reproduce it, because that needs a workspace that requires 2FA, such as one with Xero connected.
    • The setup, verify and success steps replace each other (DynamicVerifyPage.tsx:63). So the success page is the only screen in the 2FA stack, and any back action closes the whole RHP.
    • Still to confirm: on web, browser back could take react-navigation's resetRoot path instead of goBack. beforeRemove doesn't fire on that path. If it does, browser back needs a separate fix. Check this on web before you finalize the PR.
    • Home can render behind the RHP at this point because 2FA is already on. sendForcedSetupUserHome already reveals Home from the same screen.

    Related issues:


    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/105693) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.


    view run

  4. added
    External
    on Nov 2, 2026
  5. melvin-bot commented on Nov 2, 2026

    @melvin-bot

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

  6. changed the title [-]Account - System back button on 2FA success RHP navigates to Account > Security[/-] [+][$175] Account - System back button on 2FA success RHP navigates to Account > Security[/+] on Nov 2, 2026
  7. melvin-bot commented on Nov 2, 2026

    @melvin-bot

    Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.

  8. khizzcr7 commented on Nov 3, 2026

    @khizzcr7

    Root cause: the 2FA success screen sits in the RHP stack on top of Account > Security, so a system back press (Android) or browser back / click-outside (web) simply pops one level to Security instead of exiting the flow — but the expected landing after a completed 2FA setup is Home.

    Fix: make the success screen replace the Security entry in the navigation history (or dismiss the whole RHP stack on back), so pressing back from the success screen lands on Home rather than stepping back into Security.

    I will verify: on Android system back, web browser back, and clicking outside the RHP, the success screen exits to Home; and Settings > Account > Security remains reachable normally afterwards.

  9. kevinjosh10 commented on Nov 3, 2026

    @kevinjosh10

    Proposal

    What is the root cause of that problem?

    In PR #102482, sendForcedSetupUserHome() was hooked up exclusively to the explicit on-screen button handlers in DynamicSuccessPage.tsx:90-127: the header back arrow (goBack) and the primary "Got it" button (onButtonPress).

    DynamicSuccessPage does not intercept stack removal events. Consequently, when a user exits via:

    1. Android hardware / system back button,
    2. Clicking the modal backdrop overlay outside the RHP on web (handleOverlayPress in RightModalNavigator.tsx:250),
    3. Browser back button (popstate), or
    4. Keyboard Escape key,

    React Navigation directly pops the RightModalNavigator off the root navigation stack. Because the forced 2FA flow was opened on top of settings/security?forceSetup=true (RequireTwoFactorAuthenticationOverlay.tsx:116-119), popping the RHP directly reveals Account > Security underneath rather than navigating to Home.

    Furthermore, in DynamicSuccessPage.tsx:

    const isForcedSetupFlow = isSecuritySettingsFlow && route.params?.forceSetup === 'true';

    isForcedSetupFlow is coupled to isSecuritySettingsFlow (dynamically derived from getStateFromPath(dynamicBackPath)). Once Navigation.revealRouteBeforeDismissingModal(ROUTES.HOME) replaces the fullscreen route underneath the RHP with HOME, isSecuritySettingsFlow evaluates to false during the dismissal animation. The forced setup status must be derived authoritatively from route.params?.forceSetup === 'true'.

    (Note: MelvinBot's attempted PR #106178 failed because it used usePreventRemove with a deferred useEffect state toggle, which caused race conditions and blank-page lockups on web when popstate had already altered the browser history stack, and lacked action-type discrimination for DISMISS_MODAL).


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

    1. Derive isForcedSetup directly from screen route params

    In src/pages/settings/Security/TwoFactorAuth/DynamicSuccessPage.tsx:

    • Decouple the forced-setup check from the underlying route so it remains stable throughout the entire lifecycle of the screen:
      const isForcedSetup = route.params?.forceSetup === 'true';

    2. Intercept Screen Removal via a beforeRemove Navigation Listener

    In DynamicSuccessPage.tsx, register a beforeRemove listener on navigation active during forced setup (isForcedSetup || shouldReturnToOnboardingAfter2FA):

    • Intercept any unhandled removal actions (Android back, overlay click, browser back, Escape key):
      • Prevent default removal (e.preventDefault()).
      • Use an isExitingRef to prevent re-entrant duplicate triggers from rapid clicks.
      • Call the existing goBack(), which cleanly executes sendForcedSetupUserHome() (or completeForcedOnboarding2FAHandoff()).
    • Allow the final dismiss action through:
      • When sendForcedSetupUserHome() executes, it calls Navigation.revealRouteBeforeDismissingModal(ROUTES.HOME), which dispatches CONST.NAVIGATION.ACTION_TYPE.DISMISS_MODAL.
      • When e.data.action.type === CONST.NAVIGATION.ACTION_TYPE.DISMISS_MODAL, allow the action to proceed unimpeded so the RHP slides out smoothly over Home.
    const isExitingRef = useRef(false);
    
    useEffect(() => {
        if (!isForcedSetup && !shouldReturnToOnboardingAfter2FA) {
            return;
        }
    
        const unsubscribe = navigation.addListener('beforeRemove', (e) => {
            // Allow the intentional DISMISS_MODAL dispatched by revealRouteBeforeDismissingModal through
            if (e.data.action.type === CONST.NAVIGATION.ACTION_TYPE.DISMISS_MODAL) {
                return;
            }
    
            e.preventDefault();
    
            if (isExitingRef.current) {
                return;
            }
            isExitingRef.current = true;
    
            goBack();
        });
    
        return unsubscribe;
    }, [isForcedSetup, shouldReturnToOnboardingAfter2FA, navigation, goBack]);

    3. Preserve Voluntary 2FA Setup

    When a user sets up 2FA voluntarily from Settings > Security (without forceSetup=true):

    • isForcedSetup is false.
    • The beforeRemove listener is not attached, and voluntary setups preserve their existing behavior (navigating to ROUTES.SETTINGS_2FA_ENABLED via onButtonPress).

    4. Before and After Results

    Before (on main):

    After (with our fix):

    • Completing forced 2FA setup lands on 2FA Success page.
    • Pressing Android system back, clicking outside the modal overlay, or pressing browser back is intercepted by the beforeRemove listener, executing sendForcedSetupUserHome(), smoothly dismissing the RHP, and landing the user on Home (/home) with zero blank pages:
      • Screenshot of expected outcome (lands on Home):
        After: Home is focused
    Verification Matrix Expected Result Actual Result with Fix
    Android Hardware Back Button Navigate to Home (/home) ✅ Lands on Home
    Modal Backdrop Overlay Click (Web) Navigate to Home (/home) ✅ Lands on Home
    Browser Back Button (Web) Navigate to Home (/home) ✅ Lands on Home
    Keyboard Escape Key Navigate to Home (/home) ✅ Lands on Home
    Voluntary 2FA Setup (from Settings) Keep on Enabled Page (SETTINGS_2FA_ENABLED) ✅ Stays on Enabled Page
    Incomplete Onboarding Forced 2FA Resume Onboarding Handoff ✅ Resumes Onboarding

    5. Automated Tests

    In tests/unit/pages/settings/Security/TwoFactorAuth/DynamicSuccessPageTest.tsx:

    • Add test asserting that dismissing the RHP via Android system back or overlay click when forceSetup === 'true' navigates to ROUTES.HOME.
    • Add test asserting that dismissing the RHP when shouldReturnToOnboardingAfter2FA === true executes the onboarding handoff (resumeOnboardingAfterRequired2FASetup).
    • Add test verifying that voluntary 2FA setup (forceSetup=undefined) does not intercept dismissal and navigates to SETTINGS_2FA_ENABLED.

    What alternative solutions did you explore? (Optional)

    1. useAndroidBackButtonHandler: Only intercepts the Android hardware back button; leaves modal backdrop clicks, keyboard Escape, and web browser back still revealing Settings > Security.
    2. usePreventRemove with state toggling in useEffect (PR Route forced two-factor success dismissals to Home #106178): Causes race conditions on web when browser popstate has already altered history, leading to blank page freezes and broken second-back navigation.
    3. Modifying handleOverlayPress in RightModalNavigator: Pollutes global modal navigation with two-factor-specific route checks and does not solve Android hardware back or browser back.

    Contributor details

    Your Expensify account email: lkevinjosh10@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~0131dae36abcf59374

  10. sumit-2007-git commented on Nov 3, 2026

    @sumit-2007-git

    Proposal

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

    In a forced 2FA setup flow (e.g. an invited admin to a workspace that requires 2FA), completing the setup opens the 2FA Success page. Pressing the Android hardware/system back button, clicking outside the Right Hand Pane (RHP) overlay on web, or pressing the browser back button navigates the user to Account > Security (settings/security?forceSetup=true) instead of navigating them to Home.

    What is the root cause of that problem?

    In src/pages/settings/Security/TwoFactorAuth/DynamicSuccessPage.tsx (lines 90-127):
    sendForcedSetupUserHome() is only hooked up to the header back button (onBackButtonPress={goBack}) and the primary "Got it" button (onButtonPress).

    When a user:

    1. Presses the Android hardware back button,
    2. Clicks outside the RHP modal overlay (triggering handleOverlayPress in RightModalNavigator.tsx), or
    3. Uses the browser back button,

    the dismissal bypasses goBack() and executes directly on the root/modal stack navigator. Because the 2FA flow was initiated from settings/security?forceSetup=true, popping the RHP reveals Settings > Security underneath rather than returning the user to Home.

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

    In src/pages/settings/Security/TwoFactorAuth/DynamicSuccessPage.tsx:

    1. Import usePreventRemove from @react-navigation/native and useRef from react.
    2. Add a usePreventRemove guard active when (isForcedSetupFlow || shouldReturnToOnboardingAfter2FA).
    3. Use a isDismissingRef flag to prevent blocking our custom dismissal:
    --- a/src/pages/settings/Security/TwoFactorAuth/DynamicSuccessPage.tsx
    +++ b/src/pages/settings/Security/TwoFactorAuth/DynamicSuccessPage.tsx
    @@ -29,8 +29,8 @@ import ONYXKEYS from '@src/ONYXKEYS';
     import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES';
     import SCREENS from '@src/SCREENS';
     import {hasCompletedGuidedSetupFlowSelector} from '@src/selectors/Onboarding';
     import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
    -import {findFocusedRoute} from '@react-navigation/native';
    +import {findFocusedRoute, usePreventRemove} from '@react-navigation/native';
     import {authTokenTypeSelector} from '@selectors/Session';
    -import React from 'react';
    +import React, {useRef} from 'react';
     import SuccessPageBase from './SuccessPageBase';
    @@ -53,4 +53,12 @@ function DynamicSuccessPage({route}: DynamicSuccessPageProps) {
         const isForcedSetupFlow = isSecuritySettingsFlow && route.params?.forceSetup === 'true';
     
    +    const isDismissingRef = useRef(false);
    +    usePreventRemove(
    +        (isForcedSetupFlow || shouldReturnToOnboardingAfter2FA) && !isDismissingRef.current,
    +        () => {
    +            isDismissingRef.current = true;
    +            goBack();
    +        },
    +    );

    When beforeRemove is intercepted, goBack() is triggered, properly executing sendForcedSetupUserHome() or completeForcedOnboarding2FAHandoff() to navigate the user to Home.

    What alternative solutions did you explore? (Optional)

    • Using useAndroidBackButtonHandler: This only handles Android hardware back and leaves click-outside-overlay and browser back still falling back to Settings > Security. usePreventRemove intercepts all screen removal actions uniformly.

    What automated tests can you add to prevent this from re-occurring?

    In tests/unit/DynamicSuccessPageTest.tsx:

    • Verify that when isForcedSetupFlow === true, triggering a beforeRemove event on the navigation container executes sendForcedSetupUserHome().
    • Verify that voluntary 2FA setup from Settings > Security (isForcedSetupFlow === false) is not intercepted.

    Contributor Track Record & Details

    • Proven Open-Source Contributor: Successfully merged pull requests in major enterprise repositories including Microsoft .NET runtime (PR reference: dotnet/runtime#136828).
    • Ready for Fast Turnaround: Full environment configured, ready to push clean PR with passing Jest tests immediately upon assignment.
  11. ayolyn commented on Nov 3, 2026

    @ayolyn

    Proposal

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

    In a forced 2FA setup flow (e.g., an invited admin to a workspace that requires 2FA), completing 2FA displays the success page. Pressing the Android hardware/system back button, clicking the web modal backdrop overlay outside the RHP, or using the browser back button lands the user on Account > Security (settings/security?forceSetup=true) instead of navigating them to Home.


    What is the root cause of that problem?

    In src/pages/settings/Security/TwoFactorAuth/DynamicSuccessPage.tsx:

    1. sendForcedSetupUserHome() (or the custom forced-setup dismissal) is only wired up to the explicit UI buttons: the header back arrow (onBackButtonPress={goBack}) and the primary button (onButtonPress).
    2. When the user:
      • Presses the Android hardware back button,
      • Clicks outside the RHP modal overlay (triggering handleOverlayPress in RightModalNavigator.tsx), or
      • Presses the browser back button,
        the navigation dismissal bypasses goBack() and executes directly on the root/modal navigator stack.
    3. Because the 2FA flow was launched on top of settings/security?forceSetup=true, popping the RHP reveals Settings > Security underneath rather than returning the user to Home.

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

    In src/pages/settings/Security/TwoFactorAuth/DynamicSuccessPage.tsx:

    1. Import usePreventRemove from @react-navigation/native and useRef from react.
    2. Add a usePreventRemove hook active when (isForcedSetupFlow || shouldReturnToOnboardingAfter2FA):
    const isDismissingRef = useRef(false);
    
    usePreventRemove(
        (isForcedSetupFlow || shouldReturnToOnboardingAfter2FA) && !isDismissingRef.current,
        () => {
            isDismissingRef.current = true;
            goBack();
        },
    );
    1. When beforeRemove is intercepted, goBack() is triggered. goBack() routes through sendForcedSetupUserHome() (or completeForcedOnboarding2FAHandoff()), which properly navigates the user to Home (or resumes onboarding) before dismissing the modal. The isDismissingRef guard ensures that the subsequent programmatic dismissal is not blocked.

    What alternative solutions did you explore? (Optional)

    • useAndroidBackButtonHandler: Explored, but rejected because it only handles Android hardware back events and leaves web backdrop clicks and browser back actions unhandled. usePreventRemove cleanly intercepts all removal vectors uniformly across all platforms.

    What automated tests can you add to prevent this from re-occurring?

    In tests/unit/DynamicSuccessPageTest.tsx:

    • Add a test verifying that when isForcedSetupFlow is true, dispatching a beforeRemove navigation event executes sendForcedSetupUserHome().
    • Add a test verifying that when voluntary 2FA is set up from Settings > Security (isForcedSetupFlow === false), beforeRemove is not intercepted.

    Contributor details

    Your Expensify account email: juliusayolyn@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~0105126232377c4c5c

  12. melvin-bot commented on Nov 3, 2026

    @melvin-bot

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

  13. 67 remaining items

  14. laveshfonix commented on Nov 12, 2026

    @laveshfonix
    Contributor

    @daledah @MariaHCD before assignment, one start where the selected proposal still lands on Account > Security: the required-2FA overlay used while the Settings tab is open (for example, the app reopened on an Account page). The setup then opens over that Settings page without forceSetup, so the success page doesn't treat it as forced, and neither browser back nor Got it sends the user Home.

    I applied the selected proposal's code as written (the replaceFullscreenUnderRHP helper and the useBeforeRemove listener) on main, and ran it locally with a real 2FA setup (the overlay shown by setting needsTwoFactorAuthSetup, as in my proposal):

    Start → exit selected proposal my proposal
    Settings > Security → browser back Account > Security Home
    Settings > Security → Got it "2FA enabled" page Home
    Settings > Profile → browser back / Got it Profile / Profile Home / Home
    E-selected-vs-this-settings-security.webm

    My proposal covers this start in part 2: a small helper keeps forceSetup under the setup when it starts inside the Settings tab, so the same exit fix applies there too.

  15. bonnhatnguyen commented on Nov 12, 2026

    @bonnhatnguyen

    Proposal

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

    When an account is required by a workspace policy to enable 2FA (needsTwoFactorAuthSetup / forceSetup=true) and completes the 2FA setup flow to reach DynamicSuccessPage, dismissing the RHP via the Android hardware back button, browser back button, Escape key, or modal backdrop overlay lands the user on Account > Security (or the underlying Settings tab route) instead of navigating to Home.

    What is the root cause of that problem?

    1. Explicit button handlers vs. implicit modal dismissal (src/pages/settings/Security/TwoFactorAuth/DynamicSuccessPage.tsx):
      In PR Send users Home after required 2FA setup instead of Settings > Security #102482, DynamicSuccessPage wired the forced-setup redirect (Navigation.revealRouteBeforeDismissingModal(ROUTES.HOME)) only into onButtonPress ("Got it") and onBackButtonPress (the header back button). When the user dismisses the RHP via Android system back, browser back, Escape, or clicking the RHP overlay backdrop, React Navigation dispatches POP / GO_BACK on the modal navigator directly without invoking onBackButtonPress, revealing SettingsSplitNavigator (Account > Security) underneath.
    2. Asynchronous frame gap in revealRouteBeforeDismissingModal on browser Back + missing forceSetup when started from the required-2FA overlay on a Settings tab:
      • Calling revealRouteBeforeDismissingModal(ROUTES.HOME) as-is inside a beforeRemove handler defers the underlying fullscreen replacement to requestAnimationFrame, racing with browser history pop (POP) on Web.
      • Additionally, if the user opens/reloads the app while already on a Settings tab route (Account > Security or Account > Profile), the required-2FA overlay opens the 2FA RHP over that Settings screen without forceSetup=true in the route params, so DynamicSuccessPage does not recognize the flow as a forced 2FA setup and leaves the user on Account > Security.

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

    1. Propagate forceSetup whenever the 2FA flow is launched from the required-2FA overlay (RequireTwoFactorAuthOverlay / TwoFactorAuthSteps):
      Ensure forceSetup: 'true' is passed in the route params (or derived when the flow was initiated while needsTwoFactorAuthSetup was active) regardless of whether the underlying fullscreen route was HOME or SETTINGS.
    2. Handle non-button dismissal synchronously in DynamicSuccessPage.tsx:
      Add a useBeforeRemove (or navigation.addListener('beforeRemove', ...)) guard on DynamicSuccessPage when isForcedSetup is true (and not already handled by the explicit button press):
      • Replace the underlying fullscreen route with ROUTES.HOME synchronously in the same navigation dispatch / before modal removal completes (replaceFullscreenUnderRHP(ROUTES.HOME) / shouldRevealImmediately: true in revealRouteBeforeDismissingModal), so Android hardware back, backdrop click, Escape, and browser back all land cleanly on ROUTES.HOME without flashing Account > Security.

    What alternative solutions did you explore? (Optional)

    Intercepting only BackHandler on Android was ruled out because it does not cover Web browser back, Escape, or clicking outside the RHP backdrop overlay.


    Contributor details:

  16. ocakciomursel-pixel commented on Nov 12, 2026

    @ocakciomursel-pixel

    Proposal

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

    When a user is required to set up 2FA from RequireTwoFactorAuthenticationOverlay and reaches the 2FA success RHP (DynamicSuccessPage), only Got it and the header back arrow navigate to Home (or resume incomplete onboarding). Dismissing the RHP via the Android system back button, Web browser back button, Escape key, or clicking outside the RHP lands on Account > Security (or the previously open Settings/RHP route) instead of Home.

    What is the root cause of that problem?

    There are two root defects in how PR #102482 wired forced-setup routing and modal exit:

    1. Non-button dismissals bypass DynamicSuccessPage's exit helpers, and deferred or unprevented removals desync useLinking / RightModalNavigator:

      • In DynamicSuccessPage.tsx#L72-L138, sendForcedSetupUserHome() and completeForcedOnboarding2FAHandoff() are only wired to onBackButtonPress (goBack) and onButtonPress.
      • Android hardware back, backdrop clicks (RightModalNavigator.tsx#L273-L291), Escape (DISMISS_MODAL), and browser back (popstate dispatching GO_BACK or RESET) remove the modal directly, exposing Settings > Security underneath.
      • Calling e.preventDefault() and deferring the swap to requestAnimationFrame via revealRouteBeforeDismissingModal (#106178, Navigation.ts#L1231-L1283) leaves root state unchanged during popstate, so useLinking runs rollbackHistory() (history.go(+1)) and races the rAF swap into a blank page. Conversely, swapping without e.preventDefault() fails on CommonActions.reset (rapid browser back overwrites Home back to Security), only pops one screen inside RightModalNavigator if another RHP was stacked underneath, and leaves an unconsumed pendingReveal in addRootHistoryRouterExtension.ts#L77-L101. Even swapping Home synchronously while keeping DISMISS_MODAL on rAF with a frozen pendingReveal (addRootHistoryRouterExtensionUtils.ts#L124) yields historyDelta = 2 - 2 - (-1) = +1 in useLinking on browser back, pushing a new history entry and leaving /settings/security at index - 1.
    2. forceSetup is attached to ROUTES.SETTINGS_SECURITY instead of DYNAMIC_ROUTES.TWO_FACTOR_AUTH_*, dropping forceSetup on Settings/RHP starts and polluting Settings_Security afterward:

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

    1. Move forceSetup ownership onto DYNAMIC_ROUTES.TWO_FACTOR_AUTH_* (src/ROUTES.ts, src/hooks/useTwoFactorAuthRoute.ts, src/libs/Navigation/types.ts, RequireTwoFactorAuthenticationOverlay.tsx, and the 2FA dynamic step pages):

      • Declare getRoute and queryParams: ['forceSetup'] on the four TWO_FACTOR_AUTH_* entries in src/ROUTES.ts (matching VERIFY_ACCOUNT / ADD_BANK_ACCOUNT_VERIFY_ACCOUNT), so getPathFromState preserves forceSetup=true on the active 2FA route while getPathWithoutDynamicSuffix automatically strips forceSetup from backPath:
      TWO_FACTOR_AUTH_ROOT: {
          path: 'two-factor-auth',
          entryScreens: ['*'],
          getRoute: (options?: {forceSetup?: boolean}) => getUrlWithParams('two-factor-auth', {forceSetup: options?.forceSetup ? 'true' : undefined}),
          queryParams: ['forceSetup'],
      },
      // Same getRoute + queryParams: ['forceSetup'] on TWO_FACTOR_AUTH_VERIFY_ACCOUNT, TWO_FACTOR_AUTH_VERIFY, and TWO_FACTOR_AUTH_SUCCESS
      • In useTwoFactorAuthRoute.ts, build the suffix with DYNAMIC_ROUTES.TWO_FACTOR_AUTH_VERIFY_ACCOUNT.getRoute(options) and DYNAMIC_ROUTES.TWO_FACTOR_AUTH_ROOT.getRoute(options), and in RequireTwoFactorAuthenticationOverlay.tsx#L118 pass clean ROUTES.SETTINGS_SECURITY.getRoute() with {forceSetup: true} (removing the forceSetup param from ROUTES.SETTINGS_SECURITY.getRoute so Settings_Security is never polluted).
      • Type {forceSetup?: string} on DYNAMIC_ROOT, DYNAMIC_VERIFY_ACCOUNT, and DYNAMIC_VERIFY in TwoFactorAuthNavigatorParamList, and forward {forceSetup: route.params?.forceSetup === 'true'} in the intra-flow DYNAMIC_ROUTES.TWO_FACTOR_AUTH_*.getRoute(...) transitions in DynamicTwoFactorAuthVerifyAccountPage.tsx, DynamicTwoFactorAuthPage.tsx, and DynamicVerifyPage.tsx.
    2. Add a single-turn synchronous modal-dismiss-to-route helper for removal events (Navigation.ts, createRootStackNavigator/types.ts, addRootHistoryRouterExtension.ts):

      • Add shouldFreezeHistory?: boolean (default true) to REPLACE_FULLSCREEN_UNDER_RHP so addRootHistoryRouterExtension.ts#L77 skips getFrozenHistoryStateForReplaceFullscreenUnderRHP when action.payload.shouldFreezeHistory === false.
      • Expose Navigation.dismissModalToRoute(route, {afterTransition}) in src/libs/Navigation/Navigation.ts, which synchronously dispatches REPLACE_FULLSCREEN_UNDER_RHP (shouldFreezeHistory: false) followed immediately by dismissModal({afterTransition}) in the same turn:
      function dismissModalToRoute(route: Route, options?: {afterTransition?: () => void}) {
          if (!canNavigate('dismissModalToRoute', {route}) || !navigationRef.current) {
              return;
          }
          navigationRef.current.dispatch({
              type: CONST.NAVIGATION.ACTION_TYPE.REPLACE_FULLSCREEN_UNDER_RHP,
              payload: {route, shouldFreezeHistory: false},
          });
          dismissModal({afterTransition: options?.afterTransition});
      }

      Because both dispatches commit synchronously inside beforeRemove, root state becomes [Tab(Home)] (history.length = 1) in the same turn: useLinking sees afterState !== beforeState (no rollbackHistory()), single browser back (pendingPopStateDelta = -1) computes historyDelta = 1 - 2 - (-1) = 0 and history.replaces /settings/security in place with /home, backdrop/Escape (pendingPopStateDelta = null) pops the modal entry and replaces /settings/security with /home, RESET cannot overwrite Home, and DISMISS_MODAL closes the entire RightModalNavigator even if another RHP was open underneath.

    3. Decouple forced flags from isSecuritySettingsFlow and intercept non-button removals in DynamicSuccessPage.tsx:

      • Set const isForcedSetupFlow = route.params?.forceSetup === 'true'; and const shouldReturnToOnboardingAfter2FA = (isSecuritySettingsFlow || isForcedSetupFlow) && isForcedOnboardingHandoff;.
      • Guard explicit and implicit exits with isExitingForcedSetupRef and useBeforeRemove (src/hooks/useBeforeRemove.tsx):
      const isExitingForcedSetupRef = useRef(false);
      
      useBeforeRemove((e) => {
          if (isExitingForcedSetupRef.current || (!shouldReturnToOnboardingAfter2FA && !isForcedSetupFlow)) {
              return;
          }
          isExitingForcedSetupRef.current = true;
          e.preventDefault();
      
          if (shouldReturnToOnboardingAfter2FA) {
              clearTwoFactorAuthData(is2FAEnabled, true);
              const onboardingFlowParams = buildOnboardingFlowParams(account, onboardingValues, onboardingCompanySize, onboardingPurposeSelected, onboardingInitialPath);
              Navigation.dismissModalToRoute(ROUTES.HOME, {
                  afterTransition: () => resumeOnboardingAfterRequired2FASetup(onboardingFlowParams),
              });
              return;
          }
      
          Navigation.dismissModalToRoute(ROUTES.HOME, {
              afterTransition: () => clearTwoFactorAuthData(is2FAEnabled, true),
          });
      });

      Set isExitingForcedSetupRef.current = true at the start of completeForcedOnboarding2FAHandoff and sendForcedSetupUserHome so Got it and the header back arrow keep their existing two-frame revealRouteBeforeDismissingModal transition unimpeded, while voluntary Settings, USD bank account, and Xero 2FA flows remain untouched.

    What alternative solutions did you explore? (Optional)

    • Mutating or pre-navigating Settings_Security?forceSetup=true from RequireTwoFactorAuthenticationOverlay when on the Settings tab: Still fails when an RHP is already open (linkTo skips fullscreen matching whenever RIGHT_MODAL_NAVIGATOR is on top) and leaves forceSetup: 'true' persisted on Settings_Security in SETTINGS_SPLIT_NAVIGATOR for subsequent voluntary setups in the same session.
    • Dispatching REPLACE_FULLSCREEN_UNDER_RHP on DynamicSuccessPage mount (preInsertFullscreenUnderRHP) or inside beforeRemove without e.preventDefault(): Mount-time pre-insertion freezes history via pendingReveal and disables RHP slide animations; skipping e.preventDefault() breaks on CommonActions.reset (rapid browser back), leaks pendingReveal, and only pops one inner screen when another RHP was stacked below TwoFactorAuth.
  17. neerajbachani commented on Nov 12, 2026

    @neerajbachani
    Contributor

    @laveshfonix Thanks for running it.

    The steps in the issue start from login. On staging, Got it on that success screen already goes Home. Back is what still lands on Account > Security, and that is what the selected proposal fixes.

    Your video starts with the Settings tab already open, so the setup opens over that Account page and forceSetup never reaches the success screen. That is why Got it stays on the Enabled page and back stays on Security or Profile. I can cover that start in the PR if we want it in this issue. Thanks!!

    @MariaHCD Waiting for the assignment here, thanks!!

  18. removed
    Help Wanted
    on Nov 12, 2026
  19. melvin-bot commented on Nov 12, 2026

    @melvin-bot

    📣 @neerajbachani You have been assigned to this job!
    Please apply to the Upwork job and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
    Once you apply to this job, your Upwork ID will be stored and you will be automatically hired for future jobs!
    Keep in mind: Code of Conduct | Contributing 📖

  20. expensify-chore-bot commented on Nov 17, 2026

    @expensify-chore-bot

    @neerajbachani Huh... This is 4 days overdue. Who can take care of this?

  21. daledah commented on Nov 18, 2026

    @daledah
    Contributor

    friendly bump here @neerajbachani

  22. added
    Reviewing
    and removed
    Daily
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugExternalReviewingWeekly

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions