HIGH: [API Reliability] Fix extraneous `ReconnectApp` on refresh
Being discussed here: https://expensify.slack.com/archives/C049HHMV9SM/p1714059210537139
Often occurs in conjunction with HIGH: [Reliability] [$500] Multiple calls to GetNewerActions on report open and HIGH: [API Reliability] [$250] Multiple calls to OpenReport on signin, but seems to be a different root cause.
Actions Performed:
- Go to staging.new.expensify.com and login
- Open any report
- Refresh the page
- Observe the API calls for the
OpenAppReconnectAppandOpenReport
Expected Result:
There should be only one ReconnectApp OpenReport OpenApp calls
Actual Result:
Multiple calls for ReconnectApp OpenReport
Platforms:
Mac OS: Chrome/Safari
Screenshots/Videos:
Hey Edu here from Callstack
Updates on the OpenReport call case
Problems
There are 2 cases that I’m trying to prevent:
-
Multiple calls given different scenarios, happy path (opening the report) and multiple ReportScreen creation (navigating to the report, maybe a refresh) all happening at the same time
-
Updates on the multiple created ReportScreen, changing to another Report all reports gets updated
Solution
-
I’m storing a set of the ReportsID calling the openReport so if the reportID is already fetching no need to call it again -> it gets removed when the response comes back
-
I’m checking if the url reportID matches the active reportID (there always 1 report active), if it is active I can call the openReport
At least for now seems to be working, I'm testing and soon I can make a formal proposal or a PR if you want
I don't think that's the right solution -- we don't want to suppress multiple calls, we want to figure out why the code is even attempting to make multiple calls, and stop it.
actually, is this a dupe of: https://github.com/Expensify/App/issues/39673? Can we close this?
Actually, the OpenReport portion of this seems like a dupe; let's reduce the scope of this issue to just be fixing the extraneous calls to ReconnectApp, ok @gedu ?
@quinthar ok, The "suppress" is mainly because we create multiple ReportScreen, and even when you switch a report I saw OpenReport being called multiple times.
I will take a look at ReconnectApp
@quinthar
Looking at the code, when the site gets refreshed first it does the normal walk through, checking if the user was logged in already, which is true so it does a reconnectApp
Problem
On the other hand, the app register to the Network status, when it is registered it receives updates NetwokrConnection.ts file subscribeToNetInfo function
NetInfo.addEventListener((state) => {
// code
setOfflineStatus((state.isInternetReachable ?? false) === false);
});
Given that isInternetReachable is null for a couple of calls before getting the right value, it triggers the reconnection.
Solution
Given that the Lib for web is still experimental and in the description for isInternetReachable if it is unknown is null. Also checking the code for web they send basic information until they collect the real
const baseState = {
isInternetReachable: null,
};
// If we don't have a connection object, we return minimal information
I suggest to remove the ?? false because we only care when the isInternetReachable has a value and the Lib has created a connection object with the data in it.
I'm temporarily out of the C+ team as I'm about to go OOO, so the auto-assigning isn't working here. Tagging @tgolen on the PR to give it a quick review, otherwise once a BZ is assigned maybe they can find someone?
Job added to Upwork: https://www.upwork.com/jobs/~01008cff119674ebe1
Triggered auto assignment to Contributor Plus for review of internal employee PR - @s77rt (Internal)
Triggered auto assignment to @dylanexpensify (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.
Sorry @s77rt , needed to assign to BZ and @jjcoffee as C+ , @jjcoffee is OOO soon so he's off the GH C+ team.
Hiya! @mallenexpensify mind confirming what's needed here?
@dylanexpensify The PR hasn't hit staging yet, but eventually payment will be due for C+ review.
What's the next step here? Who's doing it? What is the ETA?
So we just need to pay this out?
Yep this was only deployed to staging so far though
Still waiting then!
Hit prod on 23rd, tomorrow will pay out!
Payment Summary
- Contributor: @gedu is from an agency-contributor and not due payment
- ROLE: @jjcoffee paid $(AMOUNT) via Upwork (LINK)
BugZero Checklist (@dylanexpensify)
- [ ] I have verified the correct assignees and roles are listed above and updated the neccesary manual offers
- [ ] I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/1787505314359492608/hired)
- [ ] I have paid out the Upwork contracts or cancelled the ones that are incorrect
- [ ] I have verified the payment summary above is correct
@dylanexpensify Friendly bump for payment :bow:
Sorry, on it now! Thanks @jjcoffee!
Invited to apply!
@dylanexpensify Thank you, I've applied! :pray:
@dylanexpensify Friendly bump :bow:
@jjcoffee sent offer, sorry!
@dylanexpensify No worries! I've accepted the offer now.
done!