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

Add shouldCreateNewPolicy param to getPolicySummaries action #5706

Merged
merged 11 commits into from
Oct 8, 2021

Conversation

roryabraham
Copy link
Contributor

@roryabraham roryabraham commented Oct 6, 2021

Details

This PR fixes two related race conditions:

LoginWithShortLivedTokenPage race condition explanation

  1. Page loads, beta/session props are not present yet.
  2. Calls Session.signInWithShortLivedToken
  3. Before call to API.createLogin or betas load, LogInWithShortLivedTokenPage immediately runs this.setState({hasRun: true});
  4. In componentDidUpdate, this.state.hasRun is true, and then we are stuck in LogInWithShortLivedTokenPage / infinite spinner forever.

LoginWithShortLivedTokenPage race condition fix

Get rid of hasRun state just navigate to exitTo once betas are loaded and we are logged into the correct account.

Policy load/creation race condition explanation

  1. We send an API request to create the policy
  2. We send API requests to fetch existing policies.
  3. First API request returns and policy is added to Onyx.
  4. Second API request(s) return, but at the time when the API was collecting the list of policies to send in the response, the new policy hadn't been created yet. So it's missing from this response and we remove it from Onyx.

Policy load/creation race condition fix

  1. Have AuthScreens determine if we are on /transition + if we are going to exitTo /workspace/new. Those conditions tell us if we should create a new policy.
  2. Create a new action that will optionally create a new policy before loading the full policy list and updating Onyx.
    • Note: we were previously loading policy summaries and full policies back-to-back. Instead, we just load full policies and use that to save a simplified object to Onyx. We can revisit later to load full policies only when absolutely needed, but what we have here seems no worse than what we had before.
  3. Once the route is loaded in AuthScreens, we will call the new API with shouldCreateFreePolicy.

Fixed Issues

$ #5518

Tests / QA Steps

  1. Sign into a new account on OldDot mWeb
  2. Click Set up my company for free
  3. Verify that:
    1. you are taken to NewDot
    2. logged into the new account
    3. a workspace has been created
    4. you are navigated to the page for the new workspace.

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

@roryabraham roryabraham self-assigned this Oct 6, 2021
@roryabraham roryabraham marked this pull request as ready for review October 8, 2021 00:16
@roryabraham roryabraham requested a review from a team as a code owner October 8, 2021 00:16
@MelvinBot MelvinBot requested review from mountiny and removed request for a team October 8, 2021 00:16
Copy link
Contributor

@marcaaron marcaaron left a comment

Choose a reason for hiding this comment

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

Looks great just left a couple minor comments.

src/libs/actions/Policy.js Outdated Show resolved Hide resolved
src/pages/LogInWithShortLivedTokenPage.js Show resolved Hide resolved
src/pages/LogInWithShortLivedTokenPage.js Outdated Show resolved Hide resolved
src/libs/actions/Policy.js Outdated Show resolved Hide resolved
@roryabraham
Copy link
Contributor Author

Updated!

}).then(() => {
if (shouldAutomaticallyReroute) {
Navigation.dismissModal();
Navigation.navigate(ROUTES.getWorkspaceCardRoute(res.policyID));
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh this is also accessing the policyID

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

Looks great Rory! +1 for checking if the policyID is set as Marc mentioned above.

@roryabraham
Copy link
Contributor Author

roryabraham commented Oct 8, 2021

Thanks for the reviews @marcaaron and @mountiny! I made some updates to this PR (bringing back the Get?returnValueList=policySummaryList API call) such that the getPolicyList action is now an all-in-one that does the following:

  1. Optionally creates a new policy
  2. Loads policy summaries
  3. Then optionally redirects to the new policy
  4. Then loads full policies.

That way, we're not waiting for full policies to load before rerouting to the new policy (only waiting for policySummaries). We are still loading the full list of full policies, but we could probably stop doing that once https://github.com/Expensify/Auth/pull/6019 is done. It also might not end up being a problem if https://github.com/Expensify/Auth/pull/6002 works out well.

Copy link
Contributor

@marcaaron marcaaron left a comment

Choose a reason for hiding this comment

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

LGTM. Left some non blocker comments.


if (shouldCreateNewPolicy) {
Navigation.dismissModal();
Navigation.navigate(newPolicyID ? ROUTES.getWorkspaceCardRoute(newPolicyID) : ROUTES.HOME);
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB, might be good to leave a comment about why we need to navigate to the / when there is no newPolicyID - although doesn't seem likely to happen.

* More specifically, this action will:
* 1. Optionally create a new policy.
* 2. Fetch policy summaries.
* 3. Optionally navigate to the new policy.
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB, this makes it sound like there is another option to navigate to a created policy. But what actually happens is... if the policy is created we navigate to it.

@marcaaron marcaaron merged commit 30ce47c into main Oct 8, 2021
@marcaaron marcaaron deleted the Rory-FixLoadingSpinnerRaceCondition branch October 8, 2021 18:14
@OSBotify
Copy link
Contributor

OSBotify commented Oct 8, 2021

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

github-actions bot pushed a commit that referenced this pull request Oct 14, 2021
…dition

Add shouldCreateNewPolicy param to getPolicySummaries action

(cherry picked from commit 30ce47c)
@OSBotify
Copy link
Contributor

🚀 Cherry-picked to staging by @AndrewGable in version: 1.1.7-18 🚀

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

@Expensify/applauseleads please QA this PR and check it off on the deploy checklist if it passes.

@isagoico
Copy link

I think this is not QAble by us and should be internal - Left a comment with more info here https://expensify.slack.com/archives/C9YU7BX5M/p1634265038218100

We were trying to test this #5706 and I think this might be internal QA. I'm not able to reach the option to "Click Set up my company for free " using a gmail account. If I use a domain account it will always ask me to validate before logging in.

@roryabraham
Copy link
Contributor Author

Verified and checked off

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @AndrewGable in version: 1.1.7-24 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by @marcaaron in version: 1.1.7-25 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @roryabraham in version: 1.1.8-9 🚀

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.

None yet

5 participants