Skip to content

[Awaiting checklist] [$250] iOS Xero - Navigation issue when tapping app back button three times after exiting 2FA setup #50695

Closed

Description

@IuliiaHerets

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.48-0
Reproducible in staging?: Y
Reproducible in production?: Y
Email or phone of affected tester (no customers): applausetester+kh081006@applause.expensifail.com
Issue reported by: Applause Internal Team

Action Performed:

  1. Launch New Expensify app.
  2. Go to workspace settings > Accounting.
  3. Tap Connect next to Xero.
  4. Tap Enable two-factor authentication.
  5. Tap app back button.
  6. Tap app back button again.
  7. Note that now app returns to workspace editor.
  8. Tap app back button again.

Expected Result:

App will return to workspace list.

Actual Result:

App returns to Accounting.

Workaround:

Unknown

Platforms:

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Bug6633335_1728817384645.ScreenRecording_10-13-2024_18-53-12_1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021845826997685288640
  • Upwork Job ID: 1845826997685288640
  • Last Price Increase: 2024-10-28
  • Automatic offers:
    • FitseTLT | Contributor | 104667848
Issue OwnerCurrent Issue Owner: @hoangzinh

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Oct 13, 2024
  2. melvin-bot commented on Oct 13, 2024

    @melvin-bot

    Triggered auto assignment to @twisterdotcom (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  3. IuliiaHerets commented on Oct 13, 2024

    @IuliiaHerets
    Author

    We think that this bug might be related to #wave-collect - Release 2

  4. IuliiaHerets commented on Oct 13, 2024

    @IuliiaHerets
    Author

    @twisterdotcom FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

  5. Shahidullah-Muffakir commented on Oct 13, 2024

    @Shahidullah-Muffakir
    Contributor

    Edited by proposal-police: This proposal was edited at 2024-10-20 17:59:03 UTC.

    Proposal

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

    1. When connecting to Xero, after opening the two-factor authentication modal and tapping the back button multiple times, the app stays in the Accounting page instead returning to the expected Workspace list.
    2. This issue does not occur when connecting to NetSuite, and others, where the navigation behaves as expected.

    What is the root cause of that problem?

    we pass the backTo route to it here:

    onBackButtonPress={() => TwoFactorAuthActions.quitAndNavigateBack(backTo)}

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

    We don't need to pass the backTo

    onBackButtonPress={() => TwoFactorAuthActions.quitAndNavigateBack(backTo)}

    just write:
    onBackButtonPress={() => TwoFactorAuthActions.quitAndNavigateBack()}

    this change solve the issue mentioned in the OP, and does not cause any regression for 2FA used in the Security page,.

    How does the above change work when visiting 2FA page directly via URL - How is the accounting page added as the backTo in the navigation stack?

    When we open the 2FA page directly through the URL with the backTo parameter, the app still knows where to go back because:

    1. The URL's backTo parameter (settings/workspaces/{workspaceId}/accounting) is processed by getMatchingRootRouteForRHPRoute function, which:

      • Takes this URL and converts it to a navigation state using getStateFromPath(route.params.backTo, config)
      • Checks for the target screen type (RHP navigator, full screen navigator, or central pane screen)
      • In our case, it finds that the accounting page is FullScreenNavigator
    2. The app then uses this information to set up the correct navigation stack, even though we didn't navigate there step by step. This happens in the getAdaptedState function, which:

      • Sets up the proper bottom tab navigator
      • Adds the matching central pane route (accounting page in our case)
      • Adds the RHP navigator (2FA screen)

    So even when accessing the 2FA page directly, the backTo parameter helps the app reconstruct the proper navigation stack context. That's why when we click the back button (which calls navigation.goBack()), it knows to take us back to the accounting page.

    We can actually verify this behavior by testing: if we remove the backTo parameter from the URL, the back navigation won't work as expected because the app won't have the information needed to reconstruct the proper navigation stack. This is because the logic in getMatchingRootRouteForRHPRoute specifically checks for and relies on this parameter:

    if (route.params && 'backTo' in route.params && typeof route.params.backTo === 'string') {
        const stateForBackTo = getStateFromPath(route.params.backTo, config);
        if (stateForBackTo) {
            // If we know that backTo targets the root route (full screen) we want to use it.
                const fullScreenNavigator = stateForBackTo.routes.find((rt) => rt.name === NAVIGATORS.FULL_SCREEN_NAVIGATOR);
                if (fullScreenNavigator && fullScreenNavigator.state) {
                    return fullScreenNavigator as NavigationPartialRoute<CentralPaneName | typeof NAVIGATORS.FULL_SCREEN_NAVIGATOR>;
                }
        }
    }

    FullScreenNavigator will have settings/workspaces/{workspaceId}/accounting as path with it.

    // If we know that backTo targets the root route (full screen) we want to use it.
    const fullScreenNavigator = stateForBackTo.routes.find((rt) => rt.name === NAVIGATORS.FULL_SCREEN_NAVIGATOR);
    if (fullScreenNavigator && fullScreenNavigator.state) {
    return fullScreenNavigator as NavigationPartialRoute<CentralPaneName | typeof NAVIGATORS.FULL_SCREEN_NAVIGATOR>;
    }

    here is all the related code:

    function getMatchingRootRouteForRHPRoute(route: NavigationPartialRoute): NavigationPartialRoute<CentralPaneName | typeof NAVIGATORS.FULL_SCREEN_NAVIGATOR> | undefined {
    // Check for backTo param. One screen with different backTo value may need diferent screens visible under the overlay.
    if (route.params && 'backTo' in route.params && typeof route.params.backTo === 'string') {
    const stateForBackTo = getStateFromPath(route.params.backTo, config);
    if (stateForBackTo) {
    // If there is rhpNavigator in the state generated for backTo url, we want to get root route matching to this rhp screen.
    const rhpNavigator = stateForBackTo.routes.find((rt) => rt.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR);
    if (rhpNavigator && rhpNavigator.state) {
    return getMatchingRootRouteForRHPRoute(findFocusedRoute(stateForBackTo) as NavigationPartialRoute);
    }

    Note: For better verification, we can add a breakpoint at getMatchingRootRouteForRHPRoute function and access the page with the direct URL (https://dev.new.expensify.com:8082/settings/security/two-factor-auth?backTo=settings%2Fworkspaces%2F{workspaceId}%2Faccounting&forwardTo=https%3A%2F%2Fwww.expensify.com%2Fapi%2FConnectPolicyToXero%3FpolicyID%3D{workspaceId}) - this will let us inspect exactly how the backTo parameter is being processed.

    Screen.20Recording.202024-10-20.20at.2011.mp4

    iOS

    Screen.Recording.2024-10-14.at.12.26.00.AM.mov
  6. NJ-2020 commented on Oct 14, 2024

    @NJ-2020
    Contributor

    Proposal

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

    Navigation issue when tapping app back button three times after exiting 2FA setup

    What is the root cause of that problem?

    When we press the go back button inside the TwoFactorAuth page, we invoke this function

    function quitAndNavigateBack(backTo?: Route) {
    clearTwoFactorAuthData();
    Navigation.goBack(backTo);
    }

    We pass the fallback route which leads to this issue
    * @param fallbackRoute - Fallback route if pop/goBack action should, but is not possible within RHP
    * @param shouldEnforceFallback - Enforces navigation to fallback route
    * @param shouldPopToTop - Should we navigate to LHN on back press
    */
    function goBack(fallbackRoute?: Route, shouldEnforceFallback = false, shouldPopToTop = false) {

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

    Remove the backTo(fallbackRoute)

    What alternative solutions did you explore? (Optional)

  7. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Oct 14, 2024
  8. melvin-bot commented on Oct 14, 2024

    @melvin-bot
  9. changed the title [-] iOS Xero - Navigation issue when tapping app back button three times after exiting 2FA setup[/-] [+][$250] iOS Xero - Navigation issue when tapping app back button three times after exiting 2FA setup[/+] on Oct 14, 2024
  10. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Oct 14, 2024
  11. melvin-bot commented on Oct 14, 2024

    @melvin-bot

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

  12. FitseTLT commented on Oct 14, 2024

    @FitseTLT
    Contributor

    Edited by proposal-police: This proposal was edited at 2024-10-14 20:31:49 UTC.

    Proposal

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

    iOS Xero - Navigation issue when tapping app back button three times after exiting 2FA setup

    What is the root cause of that problem?

    When we press back button goBack is called with fallbackRoute

    Navigation.goBack(backTo);

    but because it is first route in the navigator it will navigate to the fallbackRoute here
    navigate(fallbackRoute, CONST.NAVIGATION.TYPE.UP);

    which will replace the 2FA route with the accounting page. That will create a duplicate workspace accounting route to the navigation state.

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

    Instead of navigating to the fallBackRoute here with Replace action we should goBack, which will play the role of REPLACE action we were using, and then navigate to the fallbackRoute

    navigate(fallbackRoute, CONST.NAVIGATION.TYPE.UP);

    navigationRef.current.goBack();
            navigate(fallbackRoute);
    

    This will create the same effect as the navigating with REPLACE and whenever the fallbackRoute is the same as the route we are going back to it will not create a duplicate route in the navigation state and instead leave it.

    What alternative solutions did you explore? (Optional)

    We can also avoid having backTo here

    onBackButtonPress={() => TwoFactorAuthActions.quitAndNavigateBack(backTo)}

    for the case of Xero so change it to

           onBackButtonPress={() =>
                    TwoFactorAuthActions.quitAndNavigateBack(route.params.forwardTo && !route.params.forwardTo?.includes(READ_COMMANDS.CONNECT_POLICY_TO_XERO) ? backTo : '')
                }
    

    because we navigate to ROUTES.SETTINGS_2FA from different flows we need it for other cases
    This will work for direct link access too because whenever full screen navigator is found in the state found from backTo of the route we add the necessary full navigator here

    // If we know that backTo targets the root route (full screen) we want to use it.
    const fullScreenNavigator = stateForBackTo.routes.find((rt) => rt.name === NAVIGATORS.FULL_SCREEN_NAVIGATOR);
    if (fullScreenNavigator && fullScreenNavigator.state) {
    return fullScreenNavigator as NavigationPartialRoute<CentralPaneName | typeof NAVIGATORS.FULL_SCREEN_NAVIGATOR>;
    }

    and as we will not remove the backTo from the route it will work perfect.

  13. 42 remaining items

  14. changed the title [-][$250] iOS Xero - Navigation issue when tapping app back button three times after exiting 2FA setup[/-] [+][HOLD for payment 2024-11-22] [$250] iOS Xero - Navigation issue when tapping app back button three times after exiting 2FA setup[/+] on Nov 15, 2024
  15. melvin-bot commented on Nov 15, 2024

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  16. melvin-bot commented on Nov 15, 2024

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.62-4 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2024-11-22. 🎊

    For reference, here are some details about the assignees on this issue:

  17. melvin-bot commented on Nov 15, 2024

    @melvin-bot

    @hoangzinh @twisterdotcom @hoangzinh The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  18. moved this from Bugs and Follow Up Issues to Hold for Payment in #expensify-bugson Nov 19, 2024
  19. twisterdotcom commented on Nov 22, 2024

    @twisterdotcom
    Contributor

    Payment Summary:

  20. changed the title [-][HOLD for payment 2024-11-22] [$250] iOS Xero - Navigation issue when tapping app back button three times after exiting 2FA setup[/-] [+][Awaiting checklist] [$250] iOS Xero - Navigation issue when tapping app back button three times after exiting 2FA setup[/+] on Nov 22, 2024
  21. hoangzinh commented on Nov 22, 2024

    @hoangzinh
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production
    • 2b. Reported on staging (deploy blocker)
    • 2c. Reported on both staging and production
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to comment: We have an issue to for long term fix this bug already RHP Navigation - Weird goBack behaviour #47534

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion: N/A

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

      Nope, I think it's just a small UX issue. Users still use the app normally.

  22. moved this from Hold for Payment to Done in #expensify-bugson Nov 22, 2024
  23. garrettmknight commented on Nov 26, 2024

    @garrettmknight
    Contributor

    $250 approved for @hoangzinh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions