Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite spinner in ND when navigating from OD #38567

Conversation

adamgrzybowski
Copy link
Contributor

@adamgrzybowski adamgrzybowski commented Mar 19, 2024

Details

Fixed Issues

$ #37332
PROPOSAL:

Tests

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  • Verify that no errors appear in the JS console

Precondition: user is logged in OD with an account that has a existing workspace without a bank account setup

  1. Navigate to inbox and Search for the inbox task "Finish setting up..."
  2. Click on "Continue Setup"
    OR
    Click the message bubble in the bottom right
  3. You shouldn't be stuck on the infinite loading spinner

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mov
MacOS: Desktop
desktop.mov

@adamgrzybowski adamgrzybowski requested a review from a team as a code owner March 19, 2024 10:58
@melvin-bot melvin-bot bot requested review from eVoloshchak and removed request for a team March 19, 2024 10:58
Copy link

melvin-bot bot commented Mar 19, 2024

@eVoloshchak Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@allroundexperts
Copy link
Contributor

allroundexperts commented Mar 19, 2024

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native

N/A

Android: mWeb Chrome
Screen.Recording.2024-03-19.at.4.23.52.PM.mov
iOS: Native

N/A

iOS: mWeb Safari
Screen.Recording.2024-03-19.at.4.20.12.PM.mov
MacOS: Chrome / Safari
Screen.Recording.2024-03-19.at.4.16.44.PM.mov
MacOS: Desktop
Screen.Recording.2024-03-19.at.4.19.17.PM.mov

@allroundexperts
Copy link
Contributor

BUG
On native, I still see an infinite loader.

Screen.Recording.2024-03-19.at.4.25.44.PM.mov
Screen.Recording.2024-03-19.at.4.22.26.PM.mov

@allroundexperts
Copy link
Contributor

allroundexperts commented Mar 19, 2024

The following transition link seems to be broken as well.

Screenshot 2024-03-19 at 4 38 32 PM

@adamgrzybowski
Copy link
Contributor Author

The following transition link seems to be broken as well.

You mean it still shows loading spinner on the web?

@adamgrzybowski
Copy link
Contributor Author

On native, I still see an infinite loader.

It's possible we need to use shouldSkipDeepLinkNavigate on all platforms. Let me experiment with it

@allroundexperts
Copy link
Contributor

The following transition link seems to be broken as well.

You mean it still shows loading spinner on the web?

Shows a not found page.

@adamgrzybowski
Copy link
Contributor Author

@allroundexperts

Shows a not found page.
This may be not related to the infinite loading spinner

I pushed changes where I apply should skip to all platforms. Could you please check it again on native?

@allroundexperts
Copy link
Contributor

Will check & get back.

@adamgrzybowski
Copy link
Contributor Author

adamgrzybowski commented Mar 19, 2024

@mountiny This is something to save as follow up. I looked at the place where this function openReportFromDeepLink is used.

// If the app is opened from a deep link, get the reportID (if exists) from the deep link and navigate to the chat report
Linking.getInitialURL().then((url) => {
    setInitialUrl(url);
    Report.openReportFromDeepLink(url ?? '');
});

// Open chat report from a deep link (only mobile native)
Linking.addEventListener('url', (state) => {
    Report.openReportFromDeepLink(state.url);
})

In both cases the comments mention that it's for reports and the function itself indicates it's for reports.

Somehow inside this function we are going through all possible urls not only reports. It may not be visible because in linkTo we have check to prevent navigating to the page we currently display. Without it we would have double navigation because of this delayed function.

The check is broken in the issue linked above because transition route is removed before this function wants to navigate for the second time.

I would say we should limit this function to handle only the reports, as comments say but this is something we need to test. There may be some side effects we are not aware.

@allroundexperts
Copy link
Contributor

Will check & get back.

No luck. Still getting the same infinite loader on native.

@adamgrzybowski
Copy link
Contributor Author

@allroundexperts Thanks for testing! That's weird. I will do some more investigation.

@adamgrzybowski
Copy link
Contributor Author

Okay next batch of informations 😄

The function that is responsible for closing the transition page (loader) and opening desired page looks like that:

function setUpPoliciesAndNavigate(session: OnyxEntry<OnyxTypes.Session>) {
    const currentUrl = getCurrentUrl();
    if (!session || !currentUrl || !currentUrl.includes('exitTo')) {
        return;
    }

    const isLoggingInAsNewUser = !!session.email && SessionUtils.isLoggingInAsNewUser(currentUrl, session.email);
    const url = new URL(currentUrl);
    const exitTo = url.searchParams.get('exitTo') as Route | null;

    // Approved Accountants and Guides can enter a flow where they make a workspace for other users,
    // and those are passed as a search parameter when using transition links
    const policyOwnerEmail = url.searchParams.get('ownerEmail') ?? '';
    const makeMeAdmin = !!url.searchParams.get('makeMeAdmin');
    const policyName = url.searchParams.get('policyName') ?? '';

    // Sign out the current user if we're transitioning with a different user
    const isTransitioning = Str.startsWith(url.pathname, Str.normalizeUrl(ROUTES.TRANSITION_BETWEEN_APPS));

    const shouldCreateFreePolicy = !isLoggingInAsNewUser && isTransitioning && exitTo === ROUTES.WORKSPACE_NEW;


    if (shouldCreateFreePolicy) {
        createWorkspaceWithPolicyDraftAndNavigateToIt(policyOwnerEmail, policyName, true, makeMeAdmin);
        return;
    }
    if (!isLoggingInAsNewUser && exitTo) {
        Navigation.waitForProtectedRoutes()
            .then(() => {
                // We must call goBack() to remove the /transition route from history
                Navigation.goBack();
                Navigation.navigate(exitTo);
            })
            .then(endSignOnTransition);
    }
}

As you may see is starts with:

const currentUrl = getCurrentUrl();

And this functions returns empty string for native platforms: const getCurrentUrl: GetCurrentUrl = () => ''

So I guess that opening this link has never worked for native, even before ideal-nav-v2 because we have this guard later

const currentUrl = getCurrentUrl();
if (!session || !currentUrl || !currentUrl.includes('exitTo')) {
    return;
}

The questions is if this PR should fix it or should it be outside of the scope. For me it feels like something different and should be handled separately. Let me know what do you think

cc: @allroundexperts @mountiny

@allroundexperts
Copy link
Contributor

Only @mountiny can answer this!

@mountiny
Copy link
Contributor

@allroundexperts @adamgrzybowski lets focus on fixing the desktop/ web redirect and the look into the native platforms redirects too

So I guess that opening this link has never worked for native, even before ideal-nav-v2 because we have this guard later

Which redirect you mean? I think deeplinks definitely worked but it might be true that the transition is not built for native, I think we would want users to go to mWeb and then they can openthe native app if they want

@allroundexperts do the transitions work in mWeb?

@allroundexperts
Copy link
Contributor

@allroundexperts do the transitions work in mWeb?

Yup, they work well on web / mweb.

@allroundexperts
Copy link
Contributor

@adamgrzybowski Let's revert to your previous web only commit so that there are no side effects.

@adamgrzybowski
Copy link
Contributor Author

Which redirect you mean? I think deeplinks definitely worked but it might be true that the transition is not built for native, I think we would want users to go to mWeb and then they can openthe native app if they want

This type of links
https://dev.new.expensify.com:8082/transition?accountID=14396984&email=adam.grzybowski%2B2%40swmansion.com&shortLivedAuthToken=tokenX&encryptedAuthToken=tokenY&exitTo=bank-account%2Fnew%3FpolicyID%3D723873F836F2BF94&shouldForceLogin=false

This url is the one that should be result of the getCurrentUrl() function. It has exitTo so we know where to navigate after transition.

But it's an empty string on native

Without this information it just return early and don't navigate and as a result we stay on the transition page with spinner.

What I did noticed that this URL is present in params in the navigation state so there should be a way to get this information. I could look for someone from SWM to handle this if you want to create and issue for that.

cc: @mountiny

@adamgrzybowski
Copy link
Contributor Author

@allroundexperts

adamgrzybowski Let's revert to your previous web only commit so that there are no side effects.

Done

Copy link
Contributor

@allroundexperts allroundexperts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified it to be working on web!

@melvin-bot melvin-bot bot requested a review from mountiny March 19, 2024 15:54
@mountiny mountiny removed the request for review from eVoloshchak March 19, 2024 16:37
@mountiny mountiny merged commit f135365 into Expensify:main Mar 19, 2024
16 checks passed
@melvin-bot melvin-bot bot added the Emergency label Mar 19, 2024
Copy link

melvin-bot bot commented Mar 19, 2024

@mountiny looks like this was merged without a test passing. Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 1.4.55-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 failure ❌
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@mountiny
Copy link
Contributor

Not an Emergency the tests were passing

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 1.4.55-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/AndrewGable in version: 1.4.55-3 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants