Skip to content

[Due for payment 2025-09-02] [$250] Copilot - Not here page appears briefly when user switches account on Subscription page #66842

Closed

Description

@jponikarchuk

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.1.84-1
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from TestRail: https://test-management.browserstack.com/projects/2148171/test-runs/TR-137/39317262/797467963?q=copilot&issue_type=jira&sort=%2Bidentifier
Email or phone of affected tester (no customers): applausetester+210702kh@applause.expensifail.com
Issue reported by: Applause Internal Team
Device used: Mac 15.5 / Chrome
App Component: User Settings

Action Performed:

Precondition

  • User has at least one workspace.
  • User is a copilot and has access to another account (Another account must provide access to this user).
  1. Go to staging.expensify.com
  2. Go to Account.
  3. Open Subscription tab.
  4. Open account switcher.
  5. Select another account.

Expected Result:

Not here page will not appear when switching account on Subscription tab.

Actual Result:

Not here page appears briefly when switching account on Subscription tab.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021948164743590231456
  • Upwork Job ID: 1948164743590231456
  • Last Price Increase: 2025-08-06
  • Automatic offers:
    • nkdengineer | Contributor | 108381881
Issue OwnerCurrent Issue Owner: @
Issue OwnerCurrent Issue Owner: @lydiabarclay

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jul 22, 2025
  2. melvin-bot commented on Jul 22, 2025

    @melvin-bot

    Triggered auto assignment to @lydiabarclay (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. Eskalifer1 commented on Jul 22, 2025

    @Eskalifer1
    Contributor

    Proposal

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

    Copilot - Not here page appears briefly when user switches account on Subscription page

    What is the root cause of that problem?

    Currently, we don't have a state that reflects Delegate loading, so at one point we have no value for subscriptionPlan and isAppLoading is false, which is why we briefly see the not-found page:

    if (!subscriptionPlan && isAppLoading) {
    return <FullScreenLoadingIndicator />;
    }
    if (!subscriptionPlan) {
    return <NotFoundPage />;
    }

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

    We need to add a state that will show the transition between accounts and use it, here are the detailed steps:

    1. Add a new key:
    DELEGATE_LOADING: 'delegateLoading',

    type OnyxValuesMapping = {

    [ONYXKEYS.DELEGATE_LOADING]: boolean;
    1. Add this key to the Preserve Value when switching between accounts:
      const KEYS_TO_PRESERVE_DELEGATE_ACCESS = [
      ONYXKEYS.NVP_TRY_FOCUS_MODE,
      ONYXKEYS.PREFERRED_THEME,
      ONYXKEYS.NVP_PREFERRED_LOCALE,
      ONYXKEYS.ARE_TRANSLATIONS_LOADING,
      ONYXKEYS.SESSION,
      ONYXKEYS.STASHED_SESSION,
      ONYXKEYS.IS_LOADING_APP,
      ONYXKEYS.HAS_LOADED_APP,
      ONYXKEYS.STASHED_CREDENTIALS,
      // We need to preserve the sidebar loaded state since we never unmount the sidebar when connecting as a delegate
      // This allows the report screen to load correctly when the delegate token expires and the delegate is returned to their original account.
      ONYXKEYS.IS_SIDEBAR_LOADED,
      ONYXKEYS.NETWORK,
      ];
     ONYXKEYS.DELEGATE_LOADING,
    1. Add a state for the connect function (and disconnect in the same way):
      const optimisticData: OnyxUpdate[] = [
      {
      onyxMethod: Onyx.METHOD.MERGE,
      key: ONYXKEYS.ACCOUNT,
      value: {
      delegatedAccess: {
      errorFields: {disconnect: null},
      },
      },
      },
      ];
    {
                onyxMethod: Onyx.METHOD.MERGE,
                key: ONYXKEYS.DELEGATE_LOADING,
                value: false,
            },
    '‘’
    https://github.com/Expensify/App/blob/233790a0bff4d6f5b65013dc0882b3bafc6e22ea/src/libs/actions/Delegate.ts#L263
    4. Give the value true at the end after all downloads:
    
    ```ts
    Onyx.merge(ONYXKEYS.DELEGATE_LOADING, false);
    1. Use this key to show fullscreen loader:
      if (!subscriptionPlan && isAppLoading) {
      return <FullScreenLoadingIndicator />;
      }
        const [isDelegateLoading] = useOnyx(ONYXKEYS.DELEGATE_LOADING, {canBeMissing: true});
    
        if ((!subscriptionPlan && isAppLoading) || (!subscriptionPlan && isDelegateLoading)) {
            return <FullScreenLoadingIndicator />;
        }

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    N/A

    What alternative solutions did you explore? (Optional)

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  4. nkdengineer commented on Jul 22, 2025

    @nkdengineer
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2025-08-07 15:36:55 UTC.

    Proposal

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

    Not here page appears briefly when switching account on Subscription tab.

    What is the root cause of that problem?

    When the user switches accounts, the onyx is clear

    .then(() => Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS))

    Then subscriptionPlan becomes undefined, and isAppLoading is still false, then the not found page appears briefly before OpenApp API is called

    if (!subscriptionPlan && isAppLoading) {
    return <FullScreenLoadingIndicator />;
    }
    if (!subscriptionPlan) {
    return <NotFoundPage />;
    }

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

    We should fallback isAppLoading as true here and

    const [isAppLoading = true] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: false});
    

    const [isAppLoading] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: false});

    Remove the loading app key from the preserve key list here. Then this key is always reset when connecting/disconnecting the delegate, and we can capture the correct loading status

    When we switch users, the acountID from the session is changed firs,t so we should get the accountID from userMetadata instead to get the correct plan

    const [userMetadata] = useOnyx(ONYXKEYS.USER_METADATA);
    
    // Filter workspaces in which user is the owner and the type is either corporate (control) or team (collect)
    const ownerPolicies = useMemo(() => getOwnedPaidPolicies(policies, userMetadata?.accountID ?? -1), [policies, userMetadata?.accountID]);
    

    const [session] = useOnyx(ONYXKEYS.SESSION);

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    None

    What alternative solutions did you explore? (Optional)

    Before we clear the onyx, set ONYXKEYS.IS_LOADING_APP to true, and we need to do the same for disconnect function.

    .then(() => Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS))

    or we can define a new field isDelegating in the session data, update this as true in the success data here and reset it after calling OpenApp API here

    and then use this data to determine the loading here belongs with isAppLoading

    if (!subscriptionPlan && isAppLoading) {
    return <FullScreenLoadingIndicator />;
    }
    if (!subscriptionPlan) {
    return <NotFoundPage />;
    }

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  5. bernhardoj commented on Jul 22, 2025

    @bernhardoj
    Contributor

    My proposal is basically the same concept as @Eskalifer1, but I had posted this before in #48246, so I'm not sure if my proposal can be considered.

    (In #48246, the C+ implemented only part of my proposal, so I updated the proposal a bit to remove the one that is already implemented.)

    Proposal

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

    Subscription page shows not found when switching account.

    What is the root cause of that problem?

    When we switch account, we clear the onyx and calls open app.

    .then(() => Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS))
    .then(() => {
    // Update authToken in Onyx and in our local variables so that API requests will use the new authToken
    updateSessionAuthTokens(response?.restrictedToken, response?.encryptedAuthToken);
    NetworkStore.setAuthToken(response?.restrictedToken ?? null);
    confirmReadyToOpenApp();
    return openApp().then(() => {

    Because the data is cleared, the subscription data is gone. We already have a code to show the loader.

    const [isAppLoading] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: false});
    if (!subscriptionPlan && isAppLoading) {
    return <FullScreenLoadingIndicator />;
    }
    if (!subscriptionPlan) {
    return <NotFoundPage />;
    }

    But this isn't enough because clearing the onyx happened first before the open app request, so not found will still show briefly.

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

    We can optimistically set the IS_LOADING_APP when switching the account (connect & disconnect) knowing that we will call open app (set it to false when fails),

    const optimisticData: OnyxUpdate[] = [
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: ONYXKEYS.ACCOUNT,
    value: {
    delegatedAccess: {
    errorFields: {
    connect: {
    [email]: null,
    },
    },
    },
    },
    },
    ];

    Or, we can introduce a new onyx key called IS_SWITCHING_ACCOUNT.
    Or, we can just add it as a new property to ACCOUNT

    account.isSwitching
    

    and also we need to preserve the key so it won't be cleared.

    const KEYS_TO_PRESERVE_DELEGATE_ACCESS = [
    ONYXKEYS.NVP_TRY_FOCUS_MODE,
    ONYXKEYS.PREFERRED_THEME,
    ONYXKEYS.NVP_PREFERRED_LOCALE,
    ONYXKEYS.ARE_TRANSLATIONS_LOADING,
    ONYXKEYS.SESSION,
    ONYXKEYS.STASHED_SESSION,
    ONYXKEYS.IS_LOADING_APP,
    ONYXKEYS.HAS_LOADED_APP,
    ONYXKEYS.STASHED_CREDENTIALS,
    // We need to preserve the sidebar loaded state since we never unmount the sidebar when connecting as a delegate
    // This allows the report screen to load correctly when the delegate token expires and the delegate is returned to their original account.
    ONYXKEYS.IS_SIDEBAR_LOADED,
    ONYXKEYS.NETWORK,
    ];

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    N/A

  6. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Jul 23, 2025
  7. changed the title [-]Copilot - Not here page appears briefly when user switches account on Subscription page[/-] [+][$250] Copilot - Not here page appears briefly when user switches account on Subscription page[/+] on Jul 23, 2025
  8. melvin-bot commented on Jul 23, 2025

    @melvin-bot
  9. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jul 23, 2025
  10. melvin-bot commented on Jul 23, 2025

    @melvin-bot

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

  11. parasharrajat commented on Jul 29, 2025

    @parasharrajat
    Member

    Reviewing it today.

  12. 41 remaining items

  13. changed the title [-][$250] Copilot - Not here page appears briefly when user switches account on Subscription page[/-] [+][Due for payment 2025-09-02] [$250] Copilot - Not here page appears briefly when user switches account on Subscription page[/+] on Aug 26, 2025
  14. melvin-bot commented on Aug 26, 2025

    @melvin-bot

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

  15. melvin-bot commented on Aug 26, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.98-12 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 2025-09-02. 🎊

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

  16. melvin-bot commented on Aug 26, 2025

    @melvin-bot

    @parasharrajat @lydiabarclay 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]

  17. parasharrajat commented on Aug 26, 2025

    @parasharrajat
    Member

    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:

    • [ x] 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 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: Fix copilot bugs #48517 (comment)

    • [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: Not needed

    • [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.

    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue: https://github.com/Expensify/Expensify/issues/543207

    Regression Test Proposal

    Precondition:

    • User has at least one workspace.
    • User is a copilot and has access to another account (Another account must provide access to this user).

    Test:

    1. Go to Account.
    2. Open Subscription tab.
    3. Open account switcher.
    4. Select another account.
    5. Verify that: Not here page will not appear when switching account on Subscription tab.

    Do we agree 👍 or 👎

  18. lydiabarclay commented on Sep 3, 2025

    @lydiabarclay
    Contributor

    Payment Summary

    Contributor: @nkdengineer paid $250 via Upwork
    Contributor+: @parasharrajat due $250 via NewDot

    ✅ Regression test filed

  19. parasharrajat commented on Sep 3, 2025

    @parasharrajat
    Member

    Payment requested as per #66842 (comment)

  20. quinthar commented on Sep 15, 2025

    @quinthar
    Contributor

    Approve $250 for @parasharrajat

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions