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

Quit early when persistedRequests is empty #3511

Merged
merged 2 commits into from
Jun 10, 2021
Merged

Conversation

TomatoToaster
Copy link
Contributor

@TomatoToaster TomatoToaster commented Jun 10, 2021

@Dal-Papa, please review when you get the chance
CC: @marcaaron, in case I'm misunderstanding how this is supposed to work.

Details

This callback was looping too quickly because of this line (which recursively calls the callback function it's in): https://github.com/Expensify/Expensify.cash/blob/afb44ff4667bb5686c81c074097af60c26913a5c/src/libs/Network.js#L42

The actual implementation of this function doesn't change. If persistedRequests is empty, networkRequestQueue = [...networkRequestQueue, ...persistedRequests]; becomes networkRequestQueue = [...networkRequestQueue, ...[]]; which essentially does nothing over and over again.

My theory for why this hasn't happened before is that Onyx wasn't fast enough to finish the Onyx.set(..., []) before the didLoadPersistedRequests = true line right after it. If it was slow, that would be set to true and this would exit early as expected. Alternatively we could swap line 42 and 43, but I think this change makes more sense.

Fixed Issues

Fixes #3485

Tests

Did QA on each of the platforms (couldn't get android to work with the offline mode though I can't do that with production either, so I think that's due to my VM)

QA Steps

In each respective platform (specifically iOS is broken),

  1. Verify you can go into offline mode and navigate around the app
  2. Send a message in offline mode.
  3. Verify that the message is sent when you go back online.

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

image

@TomatoToaster TomatoToaster requested a review from a team as a code owner June 10, 2021 10:13
@TomatoToaster TomatoToaster self-assigned this Jun 10, 2021
@MelvinBot MelvinBot requested review from Dal-Papa and removed request for a team June 10, 2021 10:14
Dal-Papa
Dal-Papa previously approved these changes Jun 10, 2021
@@ -32,7 +32,7 @@ let didLoadPersistedRequests;
Onyx.connect({
key: ONYXKEYS.NETWORK_REQUEST_QUEUE,
callback: (persistedRequests) => {
if (didLoadPersistedRequests || !persistedRequests) {
if (didLoadPersistedRequests || !persistedRequests || persistedRequests.length === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this correct? Based on the issue I just read it seems like didLoadPersistedRequests should be preventing this callback from executing - but does not because we are calling Onyx.set() before updating that variable. LMK if I've got it wrong. Probably we should...

  1. Move the didLoadPersistedRequests above the Onyx.set() in this function to solve the issue for now
  2. Fix Onyx so that keysChanged() is async (what we have before) to prevent other potential issues where we have assumed an asynchronous callback

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that solution also works, but is there a reason why we would want to continue running if have an empty array?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm still happy to switch to just do the other change though. That way we'll have close to original behavior as possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason why we would want to continue running if have an empty array

No, I can't really think of one. But it's not the issue we are trying to fix here and doesn't seem to be causing any specific problem for us.

@TomatoToaster
Copy link
Contributor Author

TomatoToaster commented Jun 10, 2021

Updated and tested it works on iOS and the others I've checked off on the list 👍🏾

@marcaaron marcaaron merged commit c9146a4 into main Jun 10, 2021
@marcaaron marcaaron deleted the amal-net-queue-exit branch June 10, 2021 18:53
@OSBotify
Copy link
Contributor

🚀 Deployed to staging in version: 1.0.66-13🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production in version: 1.0.68-4🚀

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.

iOS - App crashes after turning off the internet connection
4 participants