App icon indicating copy to clipboard operation
App copied to clipboard

[$250] Travel card -"Let's make sure it's you" page is displayed after tapping back arrow

Open izarutskaya opened this issue 2 weeks ago • 100 comments

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


Version Number: v9.5.37-1 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://github.com/Expensify/App/pull/106553 Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: Applause-Internal Team Slack conversation (hyperlinked to channel name):

Action Performed:

Preconditions: The account has the Travel and Consolidated Travel Billing features enabled with a bank account set up.

  1. Open the Expensify app
  2. Go to Account > Wallet
  3. Tap on Travel CVV
  4. Tap the back arrow button in the app

Expected Result:

The CVV card page is displayed after tapping the back arrow button once.

Actual Result:

The "Let's make sure it's you" page is displayed again after tapping the back arrow button once.

Workaround:

Unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

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

Screenshots/Videos

https://github.com/user-attachments/assets/0aae8fe0-8309-40b0-aa55-175fb0a5b9b5

View all open jobs on GitHub

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

izarutskaya avatar Nov 12 '26 22:11 izarutskaya

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

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

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

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

🤖 Web test steps verification results: ⚠️ partial

The app and Wallet were reached on dev NewDot web. Missing prerequisites blocked Travel CVV testing; the reported bug was not reproduced or verified.

Wallet with no configured bank account or Travel CVV entry
Step Status
Open ExpensifyThe authenticated app opened.
✅
Go to Account > WalletWallet was reached successfully.
✅
Tap Travel CVVBlocked: no Travel CVV entry appeared. Wallet showed “Add a bank account to make or receive payments.”
Wallet with no configured bank account or Travel CVV entry
⚠️
Tap the in-app back arrow onceUnverified because Travel CVV could not be opened.
⚠️

⚠️ Preliminary analysis — low confidence in the root cause

Findings: The reported release already contains protections that should prevent this behavior:

Remaining hypothesis: If Back recreates the CVV page instead of returning to the existing instance, its navigation guard resets and verification could immediately reopen. Navigation has a replacement fallback when it cannot return to the target route: Navigation.ts:614–637. That prerequisite has not been demonstrated. Alternatively, Back might leave the original verification screen unchanged.

Next diagnostic step: On an eligible account, capture route names/keys and CVV mount/unmount events immediately before and after one in-app Back press. This distinguishes a replacement/reopen from an ineffective Back action. Do not capture CVV values or verification codes.

No code fix or offending PR is established by the available evidence; changing the back destination would not address a demonstrated defect.


Next Steps: Reply with @MelvinBot <your feedback> to refine this analysis.


view run · view recording

MelvinBot avatar Nov 12 '26 22:11 MelvinBot

Proposal

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

On the Travel CVV page, the app automatically opens the "Let's make sure it's you" (validate code) page. When the user taps the back arrow on that page, they should land on the Travel CVV page, but the validate code page opens again.

What is the root cause of that problem?

The guard that stops TravelCVVPage from auto-opening the verify page again is local to the component instance:

  • hasAutoNavigatedRef is a useRef in src/pages/settings/Wallet/TravelCVVPage/TravelCVVPage.tsx (around lines 65–105).
  • The second guard, isVerifyAccountInStack, is only true while TRAVEL_CVV_VERIFY_ACCOUNT is still in the navigation state.

When the user presses back on the verify page, TravelCVVVerifyAccountPage calls Navigation.goBack(ROUTES.SETTINGS_WALLET_TRAVEL_CVV). That pops the verify route, so isVerifyAccountInStack becomes false. If TravelCVVPage is re-mounted at that point, which can happen when goBack(route) resolves to the fallback route instead of simply popping, hasAutoNavigatedRef is reset to false. The effect then passes every check (not loading, no CVV, not a delegate, online, not locked) and calls Navigation.navigate(ROUTES.SETTINGS_WALLET_TRAVEL_CVV_VERIFY_ACCOUNT) again.

So "already auto-opened verification for this flow" is stored somewhere that doesn't survive the trip back from the verify page.

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

Store the "auto-opened once" flag in TravelCVVContextProvider, which already wraps both Travel CVV screens and lives for the whole flow, instead of in a component useRef.

  1. TravelCVVPage/types.ts and default.ts: add hasAutoOpenedVerifyAccount: boolean to the state type, and setHasAutoOpenedVerifyAccount to the actions type (default false / noop).

  2. TravelCVVContextProvider.tsx:

const [hasAutoOpenedVerifyAccount, setHasAutoOpenedVerifyAccount] = useState(false);
// add both to stateValue / actionsValue
  1. TravelCVVPage.tsx: read the flag from context and use it in place of the ref.
const {cvv, hasAutoOpenedVerifyAccount} = useTravelCVVState();
const {setCvv, setHasAutoOpenedVerifyAccount} = useTravelCVVActions();

useEffect(() => {
    if (hasAutoOpenedVerifyAccount || isVerifyAccountInStack) {
        setHasAutoOpenedVerifyAccount(true);
        return;
    }
    if (isLoadingAccount || isLoadingLockAccountDetails) {
        return;
    }
    if (cvv || isSignedInAsDelegate) {
        setHasAutoOpenedVerifyAccount(true);
        return;
    }
    if (isOffline || isAccountLocked) {
        return;
    }
    setHasAutoOpenedVerifyAccount(true);
    Navigation.navigate(ROUTES.SETTINGS_WALLET_TRAVEL_CVV_VERIFY_ACCOUNT);
}, [hasAutoOpenedVerifyAccount, isLoadingAccount, isLoadingLockAccountDetails, cvv, isSignedInAsDelegate, isOffline, isAccountLocked, isVerifyAccountInStack]);

Because the provider unmounts when the user leaves the Travel CVV flow, re-opening Travel CVV from Wallet still auto-opens verification once, as intended. Coming back from the verify page, by back arrow or by successful verification, no longer opens it a second time. The user stays on the Travel CVV page and can still tap "Reveal details" manually.

  1. (Optional hardening) In TravelCVVVerifyAccountPage.tsx, use Navigation.goBack() when the CVV route is the previous route, and only fall back to ROUTES.SETTINGS_WALLET_TRAVEL_CVV when the page was opened directly (deep link). This avoids re-creating the CVV screen on back.

I'll add a unit test that renders the flow, simulates back from the verify page, and asserts Navigation.navigate is called only once with SETTINGS_WALLET_TRAVEL_CVV_VERIFY_ACCOUNT.

What alternative solutions did you explore? (Optional)

  • Using a module-level variable instead of context. This was rejected because it would survive leaving the flow and stop the intended auto-open on the next visit.
  • Removing auto-navigation entirely. That works, but it changes the intended UX of opening verification automatically.

Hassank007 avatar Nov 12 '26 22:11 Hassank007

📣 @Hassank007! 📣 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 12 '26 22:11 melvin-bot[bot]

Proposal

What is the root cause of that problem?

  1. In src/pages/settings/Wallet/TravelCVVPage/TravelCVVPage.tsx, the auto-navigation mechanism uses two guards:

    • hasAutoNavigatedRef: a component-level useRef(false) which is reset whenever TravelCVVPage is remounted during stack transitions.
    • isVerifyAccountInStack: checks whether SCREENS.SETTINGS.WALLET.TRAVEL_CVV_VERIFY_ACCOUNT exists in state.routes. When the user taps the back arrow on TravelCVVVerifyAccountPage, the verify route is popped from the navigation stack. Consequently, isVerifyAccountInStack is false. When TravelCVVPage re-renders upon returning, hasAutoNavigatedRef is false (or reset), and isVerifyAccountInStack is false, causing the useEffect to pass all checks and auto-navigate immediately back to ROUTES.SETTINGS_WALLET_TRAVEL_CVV_VERIFY_ACCOUNT.
  2. Additionally, in TravelCVVVerifyAccountPage.tsx, navigateBack calls Navigation.goBack(ROUTES.SETTINGS_WALLET_TRAVEL_CVV) with a route argument, which routes through goUp() and dispatches a NAVIGATE action back to SETTINGS_WALLET_TRAVEL_CVV instead of cleanly popping the active verify screen with Navigation.goBack().

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

  1. Persist the auto-navigation flag across the Travel CVV flow via context:

    • In TravelCVVContextProvider, add hasAutoNavigated: boolean (defaulting to false) and a corresponding setter setHasAutoNavigated.
    • In TravelCVVPage.tsx, consume hasAutoNavigated and setHasAutoNavigated from the context actions/state instead of using the local useRef.
    • In TravelCVVPage.tsx's unmount effect (useEffect(() => () => ...)), reset setHasAutoNavigated(false) alongside setCvv(null). Because TravelCVVContextProvider is composed at the AuthScreens level and remains mounted while the user is logged in, resetting hasAutoNavigated when TravelCVVPage unmounts ensures that subsequent independent visits to Travel CVV from the Wallet page will still auto-open the verification screen as intended.
  2. Clean stack pop on cancel:

    • In TravelCVVVerifyAccountPage.tsx, update navigateBack to call Navigation.goBack() without arguments when popping back to TravelCVVPage, reserving ROUTES.SETTINGS_WALLET_TRAVEL_CVV strictly as a fallback if the navigator cannot go back.

What alternative solutions did you explore? (Optional)

Using route params on ROUTES.SETTINGS_WALLET_TRAVEL_CVV (e.g. ?cancelled=true), but utilizing the existing dedicated TravelCVVContextProvider with proper unmount cleanup keeps navigation clean and keeps state encapsulated within the Travel CVV feature.

TassioSales avatar Nov 12 '26 22:11 TassioSales

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

Hassank007 avatar Nov 12 '26 22:11 Hassank007

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

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

Proposal (updated)

What is the root cause of that problem?

Two corrections and an addition to my proposal above, after re-checking main:

  1. TravelCVVContextProvider is mounted once in AuthScreens.tsx (~L195), so it lives for the whole signed-in session, not only the Travel CVV flow.
  2. Both screens are in the same RHP stack. On a clean stack, goBack(ROUTES.SETTINGS_WALLET_TRAVEL_CVV) ends in pop(1), so the CVV page is not remounted. The bug therefore needs one of two stack states, and both end with the verify page showing again after one back press:
    • A. CVV page remounted: if canPopToRoute fails, goUp() dispatches REPLACE (Navigation.ts ~L614-620). A new TravelCVVPage mounts with hasAutoNavigatedRef = false while isVerifyAccountInStack is false, so it auto-opens verification again. The unmount cleanup setCvv(null) also wipes any revealed CVV.
    • B. Verify page pushed twice: the guard is per instance (useRef). If the auto-open runs from more than one TravelCVVPage instance, or again before the stack update lands, [CVV, VERIFY, VERIFY] is created. One back press then reveals the second verify page.

Both come from the same weakness: "auto-opened already" is tracked per component instance instead of once per visit.

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

This covers both A and B:

  1. Track the auto-open once per visit, synchronously, in the provider. In TravelCVVContextProvider, add const hasAutoOpenedVerifyAccountRef = useRef(false); and expose it through the actions context. It's a ref, not state, so it is stable and updates synchronously, and two instances or two quick effect runs can't both pass the check. Add it to types.ts / default.ts.
  2. TravelCVVPage.tsx: replace the local hasAutoNavigatedRef with the shared ref (same effect logic; set .current = true before Navigation.navigate).
  3. Reset it only at the entry point. In PaymentMethodList.tsx (Travel CVV row, ~L586): hasAutoOpenedVerifyAccountRef.current = false; before Navigation.navigate(ROUTES.SETTINGS_WALLET_TRAVEL_CVV). Each new visit from Wallet still auto-opens once. Remounts inside the flow don't reset it, so the reset is deliberately not in the unmount cleanup.
  4. Avoid the remount on back. In TravelCVVVerifyAccountPage.tsx, when the previous route is TRAVEL_CVV, call Navigation.goBack(). Keep ROUTES.SETTINGS_WALLET_TRAVEL_CVV as the fallback for deep links.

Tests: (a) back from verify → navigate(SETTINGS_WALLET_TRAVEL_CVV_VERIFY_ACCOUNT) was called once; (b) remount TravelCVVPage inside the flow → no second auto-open; (c) leave and re-enter from Wallet → auto-opens again.

Note: I couldn't reproduce this myself, because it needs a Travel + Consolidated Travel Billing account. The changes are written to work whichever of A or B happens on the tester's device.

What alternative solutions did you explore? (Optional)

  • Reset the flag in the TravelCVVPage unmount cleanup. Rejected: the remount in A runs that cleanup, so the bug comes back.
  • Store the flag as React state in the provider. Rejected: state updates are async, so it doesn't close case B.

Hassank007 avatar Nov 12 '26 23:11 Hassank007

Proposal

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

When the user taps Travel CVV under Account > Wallet, the app opens TravelCVVPage and automatically navigates to TravelCVVVerifyAccountPage ("Let's make sure it's you"). When the user taps the back arrow button once on TravelCVVVerifyAccountPage, instead of returning to and staying on TravelCVVPage, the "Let's make sure it's you" screen is displayed again.

What is the root cause of that problem?

The root cause is in src/pages/settings/Wallet/TravelCVVPage/TravelCVVPage.tsx (lines 65–105) combined with how Navigation.goBack(ROUTES.SETTINGS_WALLET_TRAVEL_CVV) in src/pages/settings/Wallet/TravelCVVPage/TravelCVVVerifyAccountPage.tsx (lines 36–38) resolves back navigation:

  1. Why a single back press re-triggers auto-navigation when TravelCVVPage is remounted (goUp fallback / REPLACE) or when two auto-navigations race:

    • In TravelCVVPage.tsx, hasAutoNavigatedRef = useRef(false) is stored on the component instance rather than across the active Travel CVV session in TravelCVVContextProvider.
    • Meanwhile, the secondary guard isVerifyAccountInStack (state.routes.some((route) => route.name === SCREENS.SETTINGS.WALLET.TRAVEL_CVV_VERIFY_ACCOUNT)) is only true while TRAVEL_CVV_VERIFY_ACCOUNT is still present in state.routes.
    • When the user presses the back arrow on TravelCVVVerifyAccountPage, navigateBack() calls Navigation.goBack(ROUTES.SETTINGS_WALLET_TRAVEL_CVV). Once TRAVEL_CVV_VERIFY_ACCOUNT is popped or replaced:
      • isVerifyAccountInStack immediately becomes false.
      • If TravelCVVPage is remounted during the back transition (for example when goUp falls back to REPLACE in src/libs/Navigation/Navigation.ts:617-620, or after a deep link / reload on /settings/wallet/travel-cvv/verify-account), the new TravelCVVPage instance starts with hasAutoNavigatedRef.current === false and isVerifyAccountInStack === false. Its useEffect immediately passes every guard and calls Navigation.navigate(ROUTES.SETTINGS_WALLET_TRAVEL_CVV_VERIFY_ACCOUNT) again.
      • Worse, if the user just completed verification (setCvv(cardDetails.cvv ?? null) followed by navigateBack() in TravelCVVVerifyAccountPage.tsx:49-50), any unmount/remount of TravelCVVPage runs useEffect(() => () => setCvv(null), [setCvv]) (TravelCVVPage.tsx:60), wiping the newly revealed CVV and immediately re-opening TravelCVVVerifyAccountPage!
      • Furthermore, because Navigation.navigate(ROUTES.SETTINGS_WALLET_TRAVEL_CVV_VERIFY_ACCOUNT) schedules navigation via Navigation.isNavigationReady().then(...), isVerifyAccountInStack does not flip to true synchronously. If TravelCVVPage remounts or a second instance renders before the navigation state commits, two TRAVEL_CVV_VERIFY_ACCOUNT routes are pushed ([TRAVEL_CVV, TRAVEL_CVV_VERIFY_ACCOUNT, TRAVEL_CVV_VERIFY_ACCOUNT]), so tapping the back arrow once pops only the top screen and leaves the duplicate verify screen visible.
  2. Why TravelCVVContextProvider lifecycle must be respected cleanly (without coupling unrelated callers like PaymentMethodList):

    • TravelCVVContextProvider is mounted at the AuthScreens level (src/libs/Navigation/AppNavigator/AuthScreens.tsx:195), so it stays mounted for the entire authenticated session.
    • However, resetting the auto-navigation flag inside PaymentMethodList.tsx (at the Wallet row onPress) is brittle because ROUTES.SETTINGS_WALLET_TRAVEL_CVV can also be reached via deep link, browser history, or goBack fallback—and resetting it unconditionally in TravelCVVPage's useEffect(() => () => ...) unmount cleanup breaks whenever TravelCVVPage remounts while TRAVEL_CVV or TRAVEL_CVV_VERIFY_ACCOUNT is still active in the navigation state.
    • Instead, cleanup should only reset cvv and the auto-navigation guard when the user has actually exited the Travel CVV flow (i.e. neither SCREENS.SETTINGS.WALLET.TRAVEL_CVV nor SCREENS.SETTINGS.WALLET.TRAVEL_CVV_VERIFY_ACCOUNT remains in the navigation state).

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

  1. Track hasAutoNavigatedRef in TravelCVVContextProvider (src/pages/settings/Wallet/TravelCVVPage/types.ts, default.ts, and TravelCVVContextProvider.tsx):
    • Add hasAutoNavigatedRef: React.MutableRefObject<boolean> (or hasAutoNavigated getter/setter backed by a synchronous ref in TravelCVVContextProvider) so that marking auto-navigation as completed is synchronous and survives any remount of TravelCVVPage within the same Travel CVV flow.
// src/pages/settings/Wallet/TravelCVVPage/TravelCVVContextProvider.tsx
const [cvv, setCvv] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(false);
const [validateError, setValidateError] = useState<Errors>({});
const hasAutoNavigatedRef = useRef(false);
  1. Update src/pages/settings/Wallet/TravelCVVPage/TravelCVVPage.tsx to use the context ref and only clear state when leaving the Travel CVV flow:
    • Replace the local hasAutoNavigatedRef with the shared hasAutoNavigatedRef from TravelCVVContextProvider.
    • When TravelCVVPage unmounts, check Navigation.isTopmostRouteModalScreen() / current root navigation state: only reset setCvv(null) and hasAutoNavigatedRef.current = false when neither SCREENS.SETTINGS.WALLET.TRAVEL_CVV nor SCREENS.SETTINGS.WALLET.TRAVEL_CVV_VERIFY_ACCOUNT is in the active stack. That way:
      • Returning from TravelCVVVerifyAccountPage (even if TravelCVVPage remounts or if the user deep-linked directly to TRAVEL_CVV_VERIFY_ACCOUNT and pressed Back) never re-opens TravelCVVVerifyAccountPage and never wipes a just-revealed cvv.
      • Closing the Travel CVV flow back to Wallet (or dismissing the RHP modal) cleanly resets both cvv and hasAutoNavigatedRef.current = false, so the next time the user taps Travel CVV from Wallet, it auto-opens verification once as intended.
// src/pages/settings/Wallet/TravelCVVPage/TravelCVVPage.tsx
const {cvv} = useTravelCVVState();
const {setCvv, hasAutoNavigatedRef} = useTravelCVVActions();

useEffect(
    () => () => {
        if (
            Navigation.isRouteInRootState(SCREENS.SETTINGS.WALLET.TRAVEL_CVV) ||
            Navigation.isRouteInRootState(SCREENS.SETTINGS.WALLET.TRAVEL_CVV_VERIFY_ACCOUNT)
        ) {
            return;
        }
        setCvv(null);
        hasAutoNavigatedRef.current = false;
    },
    [setCvv, hasAutoNavigatedRef],
);

(Or inline helper checking navigationRef.current?.getRootState() for SCREENS.SETTINGS.WALLET.TRAVEL_CVV / TRAVEL_CVV_VERIFY_ACCOUNT.)

  1. Mark hasAutoNavigatedRef.current = true inside TravelCVVVerifyAccountPage.tsx on mount as well:

    • In src/pages/settings/Wallet/TravelCVVPage/TravelCVVVerifyAccountPage.tsx, set hasAutoNavigatedRef.current = true when TravelCVVVerifyAccountPage mounts. This guarantees that even if the user opened /settings/wallet/travel-cvv/verify-account directly via deep link/reload and then tapped the back arrow (which mounts TravelCVVPage for the first time via Navigation.goBack(ROUTES.SETTINGS_WALLET_TRAVEL_CVV)), TravelCVVPage knows the user just came back from TravelCVVVerifyAccountPage and will not bounce them back to the verify page.
  2. Add UI regression tests (tests/ui/TravelCVVPageTest.tsx):

    • Verify that mounting TravelCVVPage auto-navigates to ROUTES.SETTINGS_WALLET_TRAVEL_CVV_VERIFY_ACCOUNT once.
    • Verify that pressing the back arrow from TravelCVVVerifyAccountPage (including when TravelCVVPage mounts/remounts on back) keeps the user on TravelCVVPage without calling Navigation.navigate(ROUTES.SETTINGS_WALLET_TRAVEL_CVV_VERIFY_ACCOUNT) a second time.
    • Verify that leaving the Travel CVV flow and re-entering from Wallet resets the guard and auto-navigates once again.

What alternative solutions did you explore? (Optional)

  • Resetting the ref inside PaymentMethodList.tsx's onPress handler: rejected because it couples PaymentMethodList to TravelCVVContextProvider internals and fails when entering Travel CVV via deep link or when TravelCVVPage is first mounted on goBack from a deep-linked TravelCVVVerifyAccountPage.
  • Resetting the flag unconditionally in TravelCVVPage's unmount cleanup: rejected because if TravelCVVPage unmounts/remounts during stack replacement, the cleanup resets the flag (and clears cvv), reproducing the exact bug.

cocvn157 avatar Nov 13 '26 03:11 cocvn157

Proposal

What is the root cause of that problem?

  1. Component-local auto-navigation tracking in TravelCVVPage.tsx: In src/pages/settings/Wallet/TravelCVVPage/TravelCVVPage.tsx (lines 69–105), the guard hasAutoNavigatedRef = useRef(false) is stored locally within the TravelCVVPage component instance rather than in the shared session context (TravelCVVContextProvider).
  2. Navigation stack popping vs replacement in TravelCVVVerifyAccountPage.tsx: In src/pages/settings/Wallet/TravelCVVPage/TravelCVVVerifyAccountPage.tsx (lines 36–38), navigateBack calls:
    Navigation.goBack(ROUTES.SETTINGS_WALLET_TRAVEL_CVV);
    
    Passing an explicit backToRoute causes Navigation.goBack to invoke goUp(ROUTES.SETTINGS_WALLET_TRAVEL_CVV). When canPopToRoute evaluates to false (e.g. during nested stack transitions or deep-link navigation states), goUp falls back to dispatching REPLACE (src/libs/Navigation/Navigation.ts:617-620), replacing the verification route with a brand-new TravelCVVPage instance.
  3. Re-triggering the auto-navigation effect: When TravelCVVPage mounts afresh:
    • hasAutoNavigatedRef.current initializes to false.
    • isVerifyAccountInStack (state.routes.some((route) => route.name === SCREENS.SETTINGS.WALLET.TRAVEL_CVV_VERIFY_ACCOUNT)) evaluates to false because TRAVEL_CVV_VERIFY_ACCOUNT was just replaced in the stack.
    • The unmount cleanup of the previous instance ran setCvv(null) (line 60), leaving cvv as null.
    • Consequently, all guards in useEffect pass, and Navigation.navigate(ROUTES.SETTINGS_WALLET_TRAVEL_CVV_VERIFY_ACCOUNT) is called again, bouncing the user right back into the verification screen.

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

  1. Move Auto-Navigation Guard to TravelCVVContextProvider:

    • In src/pages/settings/Wallet/TravelCVVPage/TravelCVVContextProvider.tsx, add a synchronous ref hasAutoNavigatedRef = useRef(false) to state/actions context:
      const hasAutoNavigatedRef = useRef(false);
      
    • Expose hasAutoNavigatedRef in TravelCVVActionsContextType (src/pages/settings/Wallet/TravelCVVPage/types.ts and default.ts).
    • Because hasAutoNavigatedRef is stored in the context provider, it survives any remount or replacement of TravelCVVPage within the active Travel CVV flow.
  2. Consume Shared Guard in src/pages/settings/Wallet/TravelCVVPage/TravelCVVPage.tsx:

    • Replace the local hasAutoNavigatedRef = useRef(false) with the hasAutoNavigatedRef provided by useTravelCVVActions().
    • In TravelCVVPage.tsx unmount cleanup, only reset cvv and hasAutoNavigatedRef.current = false when actually navigating away from the Travel CVV flow (i.e. neither SCREENS.SETTINGS.WALLET.TRAVEL_CVV nor SCREENS.SETTINGS.WALLET.TRAVEL_CVV_VERIFY_ACCOUNT is present in the navigation state).
  3. Standardize Back Navigation in src/pages/settings/Wallet/TravelCVVPage/TravelCVVVerifyAccountPage.tsx:

    • In navigateBack, call Navigation.goBack() directly if the previous screen in the stack is TRAVEL_CVV, avoiding the goUp fallback to REPLACE:
      const navigateBack = () => {
          Navigation.goBack(ROUTES.SETTINGS_WALLET_TRAVEL_CVV);
      };
      
    • Additionally, in TravelCVVVerifyAccountPage.tsx, ensure hasAutoNavigatedRef.current = true is set on mount so that even if the user lands directly on the verification screen via a deep link or page reload and taps Back, TravelCVVPage knows verification was already presented and will not trigger a duplicate auto-navigation.
  4. Automated Regression Tests (tests/ui/TravelCVVPageTest.tsx):

    • Test 1: On initial mount from Wallet, TravelCVVPage auto-navigates to ROUTES.SETTINGS_WALLET_TRAVEL_CVV_VERIFY_ACCOUNT exactly once.
    • Test 2: Tapping the back button on TravelCVVVerifyAccountPage returns to TravelCVVPage without triggering a second auto-navigation to TRAVEL_CVV_VERIFY_ACCOUNT.
    • Test 3: Dismissing the Travel CVV modal and re-entering from Wallet resets the guard and auto-navigates once again.

What alternative solutions did you explore? (Optional)

  • Resetting the flag inside PaymentMethodList.tsx's onPress: Rejected because it creates an unnecessary coupling between PaymentMethodList and TravelCVVContextProvider internals, and does not handle deep linking or page refresh flows.
  • Removing auto-navigation entirely: Rejected because auto-opening verification is the intended UX designed so that users do not need to manually click "Reveal Details" upon initial visit. Keeping the auto-open behavior while storing the guard in the flow provider achieves the intended UX with zero re-navigation loops.

Contributor details

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

kevinjosh10 avatar Nov 14 '26 01:11 kevinjosh10

@MelvinBot post official proposal

situchan avatar Nov 14 '26 18:11 situchan

🤖 Web test steps verification results: ⚠️ partial

The app and Wallet opened, but missing Travel CVV prerequisites blocked reproduction. Independently of existing proposals, I could not establish the root cause, so an official fix proposal would be speculative.

Wallet without a configured bank account or Travel CVV entry
Step Status
Open ExpensifyThe signed-in app opened successfully.
✅
Go to Account > WalletWallet opened successfully.
✅
Open Travel CVVBlocked: no Travel CVV entry appeared, and Wallet requested a bank account.
Wallet without a configured bank account or Travel CVV entry
⚠️
Press the in-app back arrow onceUnverified because verification was unreachable.
Independent investigation confirmed that the reported release already sets its one-time guard before opening verification: TravelCVVPage.tsx:65–105. Normal back navigation should preserve that instance; a remount has not been demonstrated.
To establish the fix, capture navigation actions, route keys, and CVV mount/unmount events on an eligible account around one Back press. This will distinguish replacement/reopening from an ineffective Back action. Do not capture CVV values or verification codes.
⚠️

view run · view recording

MelvinBot avatar Nov 14 '26 18:11 MelvinBot

@situchan Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

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

Hi @situchan 👋 — happy to take this one forward whenever you've had a chance to review.

Quick recap of my proposal (and the update) in case it helps unblock the pick: it's built to fix the bug whichever stack state actually occurs on the tester's device, since the repro needs a Travel + Consolidated Billing account:

  • Case A — TravelCVVPage remounts (when goUp() falls back to REPLACE): the local useRef guard resets and auto-opens verification again.
  • Case B — verify page pushed twice (per-instance guard + async stack update race): one back press reveals the duplicate.

Both come from the same root cause — "already auto-opened" is tracked per component instance. My fix moves that flag into TravelCVVContextProvider as a ref (synchronous, so it closes the Case B race, which React state wouldn't) and resets it only at the Wallet entry point, so re-entry still auto-opens once as intended.

Happy to raise the PR as soon as it's assigned, and glad to help with repro steps if that's the blocker. Thanks!

Hassank007 avatar Nov 19 '26 22:11 Hassank007

@situchan Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!

Claude posting on behalf of Matt:

@QichenZhu you're now the C+ on this issue. The previous C+ is no longer in the Contributor program. Next step: review the proposals.

mallenexpensify avatar Nov 23 '26 22:11 mallenexpensify

Since MelvinBot didn't post a proposal, I'm adding the Help Wanted label. Only proposals posted after the label will be reviewed. If the authors of the proposals above are still interested in this issue, please delete/hide your original proposal and post a new one below.

:sos: C+ Help Wanted

QichenZhu avatar Nov 24 '26 00:11 QichenZhu

Proposal

What is the root cause of that problem?

The Travel CVV page is never under the verify page in the first place, so Back has nothing to return to. I reproduced this in a Jest test that uses our real RootStackRouter, createRightModalNavigator and linkTo, so it doesn't need a Travel account. Here's the chain:

  1. TravelCVVPage opens the verify page from a mount effect (TravelCVVPage.tsx#L69-L105).
  2. On the first open, that effect runs in the same commit where the RHP and its Settings stack mount. React runs child effects before parent effects, and React Navigation adds a newly mounted navigator's state to its parent in that navigator's own useEffect. So when Navigation.navigate runs, the RHP route in the root state has no state yet.
  3. Because of that, getMinimalAction stops at the root (getMinimalAction.ts#L65-L67), and the action becomes a PUSH of a new RightModalNavigator on the root stack.
  4. RootStackRouter handles that as "opening a modal from a modal" and first removes the RHP on top (RootStackRouter.ts#L177-L187, GetStateForActionHandlers.ts#L816-L823). The RHP that held Travel CVV is thrown away and the new one contains only [VerifyAccount]. Travel CVV unmounts, and its hasAutoNavigatedRef is gone with it.
  5. Back calls Navigation.goBack(ROUTES.SETTINGS_WALLET_TRAVEL_CVV) (TravelCVVVerifyAccountPage.tsx#L36-L38). The CVV route isn't in the stack, so goUp replaces verify with a new Travel CVV (Navigation.ts#L617-L620). That new instance starts with a fresh ref, so it opens verify again: [TravelCVV, VerifyAccount].
  6. Modal stacks animate a replace as a pop (useModalStackScreenOptions.ts#L81), so on screen it looks like Back revealed a second verify page. That's exactly what the video shows at ~0:07: verify slides out, another verify is underneath, and Travel CVV never appears. The second Back works because the new instance has already set its ref.

The same cause also makes Android back or iOS swipe on that first verify page close the whole RHP back to Wallet, because there's nothing under verify.

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

I'd fix it where the auto-navigation happens: in TravelCVVPage, let the navigators register before we push verify. We already have a helper for this, deferNavigate (@libs/Navigation/deferNavigate):

hasAutoNavigatedRef.current = true;
deferNavigate(() => Navigation.navigate(ROUTES.SETTINGS_WALLET_TRAVEL_CVV_VERIFY_ACCOUNT));

This doesn't depend on timing luck. React runs all passive effects of a commit in one synchronous pass, so the microtask always runs after the RHP and Settings stack have added their state. linkTo then pushes verify inside the existing Settings stack: [TravelCVV, VerifyAccount]. Back pops to the same Travel CVV instance, its ref is still true, and verify doesn't open again. The existing guards (offline, locked, delegate, CVV already revealed, isVerifyAccountInStack) stay the same, and TravelCVVVerifyAccountPage doesn't change.

I'll add tests/ui/TravelCVVPageTest.tsx. It renders the real TravelCVVPage inside the real root, RHP and Settings stack navigators and checks:

  • Opening from Wallet gives [TravelCVV, VerifyAccount].
  • One press of the back arrow lands on Travel CVV.
  • Hardware or swipe back lands on Travel CVV.

On main, 0/3 pass: the stack is [VerifyAccount], then [TravelCVV, VerifyAccount] after Back, and hardware back closes the RHP. With the change, 3/3 pass. No existing test covers TravelCVVPage, and the change doesn't touch shared navigation code. I don't have a Travel-enabled account, so I haven't checked this on a device. The repro is the test above.

What alternative solutions did you explore? (Optional)

  • Push with the screen's own navigation.navigate(SCREENS.SETTINGS.WALLET.TRAVEL_CVV_VERIFY_ACCOUNT). It also gives [TravelCVV, VerifyAccount] in my test. I didn't pick it because it bypasses Navigation.navigate, which NAVIGATION.md asks us to use.
  • Make getMinimalAction descend into params.screen when a route has no state yet. That would fix any page that navigates from a mount effect inside a freshly opened RHP, but it changes routing for the whole app, which is too wide for this bug.
  • Keep the "already opened" flag outside the page. That only hides the second auto-open. The RHP is still replaced on open, so hardware or swipe back still exits to Wallet. I checked this in the same test setup.

oqildev avatar Nov 24 '26 00:11 oqildev