Skip to content

[Due for payment 2026-05-15] [Due for payment 2026-05-13] [$250] Switch flow - Page keeps on loading when click on Try New Expensify #89559

Closed

Description

@lanitochka17

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.3.66-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://test-management.browserstack.com/projects/2219752/test-runs/TR-24946/folder/13176927/41237621/1387585694
Email or phone of affected tester (no customers): emady.syed1234+newuser1234@gmail.com
Issue reported by: Applause Internal Team
Bug source: Regression TC Execution
Device used: Windows 11 / Chrome
App Component: Other

Action Performed:

  1. Open staging.new.expensify.com and login
  2. Go to account > Troubleshoot > Switch to Expensify Classic
  3. Click on Try New Expensify

Expected Result:

Switching to new Expensify should work

Actual Result:

Page keeps on loading when click on Try New Expensify

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7144509_1777922889482.Recording__933.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @mallenexpensify
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022051400482073037071
  • Upwork Job ID: 2051400482073037071
  • Last Price Increase: 2026-05-04

Activity

  1. added
    Bug
    on May 4, 2026
  2. MelvinBot commented on May 4, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    When a user switches to Expensify Classic from the Troubleshoot page and then clicks "Try New Expensify" in Classic, Classic redirects back to NewDot via a /transition?shortLivedAuthToken=xxx&exitTo=... URL. The user still has a valid session stored in IndexedDB from their previous NewDot session, so the app loads as authenticated and renders LogOutPreviousUserPage.

    The bug is in isLoggingInAsNewUser: it receives the full transition URL (e.g. https://staging.new.expensify.com/transition?shortLivedAuthToken=xxx) and passes it directly to new URLSearchParams(). Since URLSearchParams expects only a query string — not a full URL — the first parameter key is mangled (becomes https://staging.new.expensify.com/transition?shortLivedAuthToken instead of shortLivedAuthToken). More importantly, the transition URL from Classic does not contain an email parameter, so both params.get('email') and the regex fallback return null. The function then evaluates null !== sessionEmail → true, incorrectly concluding the user is "logging in as a new user".

    This triggers signOutAndRedirectToSignIn, which calls the server-side LogOut API via makeRequestWithSideEffects and waits for it to resolve before calling redirectToSignIn. During this wait, the user sees FullScreenLoadingIndicator. After sign-out completes, the user lands on LogInWithShortLivedAuthTokenPage, re-authenticates with the token, returns to LogOutPreviousUserPage, hits the same isLoggingInAsNewUser → true condition, and signs out again. The second time through, getLastShortAuthToken() prevents re-authentication, and the user either gets stuck on a loading indicator or lands on SessionExpiredPage — neither of which is the expected behavior (the app should just load normally since it's the same user).

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

    In LogOutPreviousUserPage, the isLoggingInAsNewUser check should be skipped when the transition URL has no email parameter at all. The absence of an email parameter means Classic didn't specify which user is transitioning — it simply means "continue as the current user." The function should only trigger a sign-out when a different email is explicitly present in the URL.

    The fix should be in isLoggingInAsNewUser: if neither paramsEmail nor linkedEmail (from the regex fallback) is found in the URL, return false early — no email means no evidence of a different user.

    What alternative solutions did you explore? (Optional)

    1. Fix URLSearchParams parsing: Extract just the query string before passing to URLSearchParams (e.g., new URLSearchParams(new URL(transitionURL).search)). This would fix the parsing issue but wouldn't address the core problem that the transition URL lacks an email param entirely.

    2. Have Classic include the email param: Modify the OldDot "Try New Expensify" redirect to include the user's email in the URL. This would make isLoggingInAsNewUser work correctly but requires a Classic-side change and doesn't fix the NewDot-side defensive gap.

    Supporting evidence

    Key code path:

    Possibly related issue: #88243 — similar race condition with NVP_TRY_NEW_DOT and SESSION callback timing on mobile HybridApp


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  3. added
    External
    on May 4, 2026
  4. added
    Help Wanted
    on May 4, 2026
  5. melvin-bot commented on May 4, 2026

    @melvin-bot

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

  6. changed the title [-]Switch flow - Page keeps on loading when click on Try New Expensify[/-] [+][$250] Switch flow - Page keeps on loading when click on Try New Expensify[/+] on May 4, 2026
  7. melvin-bot commented on May 4, 2026

    @melvin-bot
  8. abbasifaizan70 commented on May 4, 2026

    @abbasifaizan70
    Contributor

    Proposal

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

    After a user signs in to staging.new.expensify.com, goes to Account > Troubleshoot > Switch to Expensify Classic, and then clicks Try New Expensify from Expensify Classic, New Expensify should open normally. Instead, the New Expensify page stays on the loading screen and never finishes switching back into the New Expensify experience.

    What is the root cause of that problem?

    The handoff to Classic starts from the troubleshoot page.
    For the web flow, the menu item either routes the user through the exit survey or, when the survey was completed recently, opens Classic immediately after starting switchToOldDot.

    action() {
    if (surveyCompletedWithinLastMonth) {
    switchToOldDot('');
    openOldDotLink(CONST.OLDDOT_URLS.INBOX, true);
    return;
    }
    resetExitSurveyForm(() => {
    if (shouldOpenSurveyReasonPage) {
    Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.EXIT_SURVEY_REASON.path));
    return;
    }
    Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.EXIT_SURVEY_CONFIRM.path));
    });

                          action() {
                              if (surveyCompletedWithinLastMonth) {
                                  switchToOldDot('');
                                  openOldDotLink(CONST.OLDDOT_URLS.INBOX, true);
                                  return;
                              }
    
                              resetExitSurveyForm(() => {
                                  if (shouldOpenSurveyReasonPage) {
                                      Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.EXIT_SURVEY_REASON.path));
                                      return;
                                  }
                                  Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.EXIT_SURVEY_CONFIRM.path));
                              });
                          },

    The final exit-survey confirmation is the normal path that flips the account back to Classic.
    It has the same ordering problem: it calls switchToOldDot(exitSurveyResponse), dismisses the modal, and opens Classic in the same tab immediately afterward.

    onPress={() => {
    switchToOldDot(exitSurveyResponse);
    Navigation.dismissModal();
    openOldDotLink(CONST.OLDDOT_URLS.INBOX, true);
    }}

                        onPress={() => {
                            switchToOldDot(exitSurveyResponse);
                            Navigation.dismissModal();
                            openOldDotLink(CONST.OLDDOT_URLS.INBOX, true);
                        }}

    switchToOldDot starts the SwitchToOldDot write request but does not return or await it.
    So both callers can navigate away from New Expensify before the write that sets the account back to Classic has finished.

    function switchToOldDot(exitSurveyResponse: string | undefined) {
    const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.FORMS.EXIT_SURVEY_RESPONSE_FORM | typeof ONYXKEYS.FORMS.EXIT_SURVEY_RESPONSE_FORM_DRAFT>> = [
    {
    onyxMethod: Onyx.METHOD.SET,
    key: ONYXKEYS.FORMS.EXIT_SURVEY_RESPONSE_FORM,
    value: null,
    },
    {
    onyxMethod: Onyx.METHOD.SET,
    key: ONYXKEYS.FORMS.EXIT_SURVEY_RESPONSE_FORM_DRAFT,
    value: null,
    },
    ];
    API.write(
    WRITE_COMMANDS.SWITCH_TO_OLD_DOT,
    {
    surveyResponse: exitSurveyResponse,
    },
    {optimisticData},
    );

        API.write(
            WRITE_COMMANDS.SWITCH_TO_OLD_DOT,
            {
                surveyResponse: exitSurveyResponse,
            },
            {optimisticData},
        );

    That creates a race with the Try New Expensify button in Classic.
    If the delayed SwitchToOldDot write completes after Classic starts the Try New flow, the account can end up with the stale Classic redirect state again.

    The New Expensify decision is driven from nvp_tryNewDot.classicRedirect.dismissed: true means use Classic, false means use New Expensify.
    A stale late SwitchToOldDot write can therefore put the account back into the Classic branch right as the user is trying to return to New Expensify.

    function shouldUseOldApp(tryNewDot: TryNewDot): boolean | undefined {
    if (isLockedToNewApp(tryNewDot)) {
    return false;
    }
    if (isEmptyObject(tryNewDot) || isEmptyObject(tryNewDot.classicRedirect)) {
    return true;
    }
    return tryNewDot.classicRedirect.dismissed;
    }

    function shouldUseOldApp(tryNewDot: TryNewDot): boolean | undefined {
        if (isLockedToNewApp(tryNewDot)) {
            return false;
        }
    
        if (isEmptyObject(tryNewDot) || isEmptyObject(tryNewDot.classicRedirect)) {
            return true;
        }
    
        return tryNewDot.classicRedirect.dismissed;
    }

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

    Make switchToOldDot return the API.write promise, then wait for that promise before opening Classic. This keeps the New-to-Classic state write ordered before the user can click Try New Expensify from Classic.

    In ExitSurvey.ts, callers cannot wait for the SwitchToOldDot write because the promise is not returned.
    The only code that needs to change in this function is the API.write call.

    API.write(
    WRITE_COMMANDS.SWITCH_TO_OLD_DOT,
    {
    surveyResponse: exitSurveyResponse,
    },
    {optimisticData},
    );

        return API.write(

    In DynamicExitSurveyConfirmPage.tsx, the button currently opens Classic immediately after starting the write.
    Keep the same action, but move the dismiss/open logic into finally so the user still reaches Classic if the request fails.

    onPress={() => {
    switchToOldDot(exitSurveyResponse);
    Navigation.dismissModal();
    openOldDotLink(CONST.OLDDOT_URLS.INBOX, true);
    }}

                        onPress={() => {
                            switchToOldDot(exitSurveyResponse).finally(() => {
                                Navigation.dismissModal();
                                openOldDotLink(CONST.OLDDOT_URLS.INBOX, true);
                            });
                        }}

    In TroubleshootPage.tsx, the recent-survey shortcut has the same race because it starts switchToOldDot('') and opens Classic immediately.
    Keep that shortcut, but wait for the returned promise before opening Classic.

    action() {
    if (surveyCompletedWithinLastMonth) {
    switchToOldDot('');
    openOldDotLink(CONST.OLDDOT_URLS.INBOX, true);
    return;

                              if (surveyCompletedWithinLastMonth) {
                                  switchToOldDot('').finally(() => {
                                      openOldDotLink(CONST.OLDDOT_URLS.INBOX, true);
                                  });
                                  return;
                              }

    This keeps the same user-facing flow, but guarantees that the New-to-Classic state write is no longer racing against the Classic-to-New state write triggered by Try New Expensify. Add focused tests for both callers: mock switchToOldDot with a deferred promise, trigger the Classic navigation action, assert that openOldDotLink is not called before the promise settles, then resolve the promise and assert that openOldDotLink(CONST.OLDDOT_URLS.INBOX, true) is called.

  9. Abdulloh0109 commented on May 4, 2026

    @Abdulloh0109
    Contributor

    Proposal

    What is the root cause of that problem?

    When the user is already authenticated in NewDot and OldDot's "Try New Expensify" link redirects the browser to https://staging.new.expensify.com/transition?email=...&shortLivedAuthToken=... (no exitTo parameter, because the link is meant to drop the user back on the NewDot home), three things converge to leave the page on a permanent FullScreenLoadingIndicator:

    1. The /transition URL is loaded as a fresh full-page load on web. The session in localStorage is still valid, so AppNavigator in src/libs/Navigation/AppNavigator/AppNavigator.tsx:12-27 mounts AuthScreens, which routes SCREENS.TRANSITION_BETWEEN_APPS to LogOutPreviousUserPage (src/libs/Navigation/AppNavigator/AuthScreens.tsx:200, src/pages/LogOutPreviousUserPage.tsx:24).

    2. The first useEffect (LogOutPreviousUserPage.tsx:31-64) falls through to the bottom branch and calls signInWithShortLivedAuthToken(shortLivedAuthToken) (src/libs/actions/Session/index.ts:815-819), whose getShortLivedLoginParams (Session/index.ts:154-219) flips account.isLoading to true optimistically and back to false in finallyData.

    3. The second useEffect (LogOutPreviousUserPage.tsx:66-84) is the only path that can leave this screen. After isAccountLoading flips true → false it runs the navigation block at lines 75-81:

    Navigation.goBack();
    if (exitTo) {
    Navigation.navigate(exitTo as Route);
    }
    Because the OldDot "Try New Expensify" link does not include exitTo, only the bare Navigation.goBack() executes. On this fresh load /transition is the only entry on the AuthScreens stack, so navigationRef.current.canGoBack() returns false and Navigation.goBack (src/libs/Navigation/Navigation.ts:496-515) just logs '[Navigation] Unable to go back' and returns. No navigation happens, the spinner stays.

    The redundant safety net App.setUpPoliciesAndNavigate (src/libs/actions/App.ts:768-820), called from AuthScreensInitHandler.tsx:136, also bails out at line 780 (!currentUrl?.includes('exitTo')), so nothing else moves the user off /transition.

    Note that the supportal branch in the same file (LogOutPreviousUserPage.tsx:43-51) was already hardened against this exact pattern by commit 48067694118 (Navigate to home instead of inbox), which appended Navigation.navigate(ROUTES.HOME) after Navigation.goBack(). The non-supportal branch in the second useEffect was never given the same treatment, which is why this regression surfaces only in the standard "Try New Expensify" flow.

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

    A single edit in src/pages/LogOutPreviousUserPage.tsx, inside the second useEffect's navigation block at lines 75-81:

    • Replace the conditional if (exitTo) { Navigation.navigate(exitTo as Route); } with an unconditional navigation to exitTo when present and to ROUTES.HOME otherwise. In other words, always navigate to some route after the goBack, defaulting to home when the OldDot link omitted exitTo. This mirrors the already-deployed supportal-branch pattern at lines 44-49 (signInWithSupportAuthToken → goBack → navigate(ROUTES.HOME)).

    This makes the screen self-clearing in every case: when there is a previous route in history, goBack removes /transition; when there isn't, the explicit navigate(ROUTES.HOME) guarantees the user lands on the home screen rather than on a perpetual spinner. No edits to Navigation.ts, AuthScreensInitHandler.tsx, or setUpPoliciesAndNavigate are required, keeping the blast radius confined to the one file that owns the transition UI.

    ROUTES.HOME is already imported at line 14 of the file, so no new import is needed.

    What alternative solutions did you explore?

    • Adding 'exitTo' to OldDot's "Try New Expensify" URL builder. Out of repository — OldDot lives elsewhere — and it would still leave NewDot vulnerable to any other caller that constructs a /transition URL without exitTo. Fixing the consumer side (NewDot) is strictly more defensive.
    • Hardening Navigation.goBack itself to fall back to ROUTES.HOME when canGoBack() is false. Rejected — this would change the silent no-op contract that many other call sites rely on (e.g. dismissing modals where the desired behaviour is "do nothing if we're already at the root"), with a much larger blast radius than the actual bug warrants.
    • Calling setUpPoliciesAndNavigate even without exitTo by removing the currentUrl?.includes('exitTo') early-return at App.ts:780. Rejected — that early-return exists so the function only runs in transition contexts; loosening it would risk re-running policy bootstrap on every authenticated mount and is far broader than this fix needs.
    • Adding the getLastShortAuthToken() re-entry guard from LogInWithShortLivedAuthTokenPage.tsx:29-31 to the auth-side page. Worthwhile cleanup, but does not by itself unblock the spinner: even with the guard the second useEffect would still hit the silent goBack after the API completes once. Recommend handling separately if desired, not as part of this fix.
  10. oqildev commented on May 4, 2026

    @oqildev
    Contributor

    🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.

  11. github-actions commented on May 4, 2026

    @github-actions
    Contributor

    ⚠️ @oqildev Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.

  12. aswin-s commented on May 4, 2026

    @aswin-s
    Contributor

    Proposal

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

    When an authenticated user in New Expensify navigates to Troubleshoot, switches to Classic Expensify, and then clicks "Try New Expensify" to return, Classic redirects back with a transition URL that lacks an email parameter (because the user is the same person). The isLoggingInAsNewUser function incorrectly interprets the absence of an email parameter as evidence of a new user logging in, triggering a sign-out flow. This causes the user to be stuck on a loading screen after re-authentication, as the function's faulty logic fires repeatedly and eventually exhausts the short-lived auth token.

    What is the root cause of that problem?

    The bug originates in src/libs/SessionUtils.ts in the isLoggingInAsNewUser function (lines 10–40). When Classic redirects to NewDot via /transition?shortLivedAuthToken=...&exitTo=... (with no email parameter), the function receives a transition URL with no email information. Both paramsEmail (extracted via URLSearchParams) and linkedEmail (extracted via regex fallback) resolve to null. The final return statement evaluates null !== sessionEmail → true (since sessionEmail holds the user's actual email), causing the function to incorrectly conclude that a new user is logging in. This invokes signOutAndRedirectToSignIn in LogOutPreviousUserPage, which triggers a blocking server-side LogOut call. After re-authentication via the short-lived token, the user returns to LogOutPreviousUserPage, which re-enters the same faulty condition (still no email in the URL), signs out again, and eventually gets stuck when getLastShortAuthToken() prevents further re-authentication.

    The semantic invariant violated is this: absence of an email parameter should indicate a same-user continuation (Classic → NewDot transition), not a new-user login attempt. The working analog is the isLoggingInAsDelegate function (also in src/libs/SessionUtils.ts), which correctly returns false when the delegator email is absent—treating missing data as a legitimate scenario rather than evidence of a new user.

    function isLoggingInAsNewUser(transitionURL?: string, sessionEmail?: string): boolean {
    // The OldDot mobile app does not URL encode the parameters, but OldDot web
    // does. We don't want to deploy OldDot mobile again, so as a work around we
    // compare the session email to both the decoded and raw email from the transition link.
    const params = new URLSearchParams(transitionURL);
    const paramsEmail = params.get('email');
    const delegatorEmail = params.get('delegatorEmail');
    // If the email param matches what is stored in the session then we are
    // definitely not logging in as a new user. If delegator email matches session email
    // it means that we are login in to another account as supportal user.
    if (paramsEmail === sessionEmail || delegatorEmail === sessionEmail) {
    return false;
    }
    // If they do not match it might be due to encoding, so check the raw value
    // Capture the un-encoded text in the email param
    const emailParamRegex = /[?&]email=([^&]*)/g;
    const matches = emailParamRegex.exec(transitionURL ?? '');
    const linkedEmail = matches?.[1] ?? null;
    if (linkedEmail === sessionEmail) {
    return false;
    }
    // If URLSearchParams didn't find it (e.g. transitionURL is a full URL which
    // mangles the first query-param key), fall back to regex
    const linkedDelegatorEmail = getDelegatorEmailFromURL(transitionURL) ?? null;
    return linkedEmail !== sessionEmail && linkedDelegatorEmail !== sessionEmail;
    }

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

    1. File: src/libs/SessionUtils.ts
      Function: isLoggingInAsNewUser
      Exact edit: After line 37 (the linkedDelegatorEmail assignment), insert an early-return guard. If both linkedEmail and linkedDelegatorEmail are null, no email parameter exists in the URL at all, meaning this is a same-user continuation from Classic to NewDot—not a new-user login. Return false immediately. Without this guard, the final return statement evaluates null !== sessionEmail → true, incorrectly triggering the sign-out flow.

      const linkedDelegatorEmail = getDelegatorEmailFromURL(transitionURL) ?? null;
      
      if (linkedEmail === null && linkedDelegatorEmail === null) {
          return false;
      }
      
      return linkedEmail !== sessionEmail && linkedDelegatorEmail !== sessionEmail;

    Blast radius: Isolated to isLoggingInAsNewUser. The function has two callers: AuthScreensInitHandler (which the fix corrects for Classic→NewDot transitions) and useOnboardingFlowRouter (unaffected—real new-user onboarding URLs always carry an email parameter, so the null-guard is never reached).

    What alternative solutions did you explore?

    1. Location: src/libs/Navigation/AppNavigator/AuthScreensInitHandler.tsx
      Rejection reason: Adding a URL-shape check in AuthScreensInitHandler to skip the isLoggingInAsNewUser call would mask the semantic bug rather than fix it. The function has a contract violation (absent email = unknown user instead of same user) that affects any caller passing a no-email URL; the fix belongs in the function itself, not in the caller.

    2. Location: src/libs/SessionUtils.ts (URLSearchParams line)
      Rejection reason: Changing new URLSearchParams(transitionURL) to new URLSearchParams(new URL(transitionURL).search) fixes the key-mangling side-effect but not the root cause. The Classic transition URL has no email parameter at all, so even with correct query-string parsing, paramsEmail would be null and the final return would still evaluate null !== sessionEmail → true.

  13. 36 remaining items

  14. added
    Daily
    Awaiting Payment
    and removed
    Weekly
    on May 14, 2026
  15. melvin-bot commented on May 14, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  16. melvin-bot commented on May 15, 2026

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@mallenexpensify)

    • (if NewFeature) I have created a PR for any necessary HelpDot updates, or I confirmed no updates are necessary.
    • I have verified the correct assignees and roles are listed above and updated the necessary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/2051400482073037071/hired)
    • I have verified the PR was not reverted
    • I have applied any discounts due to bugs/regressions introduced by this PR
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  17. situchan commented on May 15, 2026

    @situchan
    Contributor

    Standard $250. There's no regression.

    I'm seeing 'revert' above

    It's wrongly reverted so immediately re-reverted again.
    Here's slack thread for context.

  18. mallenexpensify commented on May 15, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor: @gijoe0295 due $250 via NewDot
    Contributor+: @situchan due $250 via NewDot

  19. JmillsExpensify commented on May 18, 2026

    @JmillsExpensify
    Contributor

    $250 approved for @gijoe0295

  20. laurenreidexpensify commented on May 23, 2026

    @laurenreidexpensify
    Contributor

    $250 approved for @situchan

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

Metadata

Metadata

Labels

Awaiting PaymentBugDailyExternal

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions