-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Do not always clear Onyx VBA data when accessing workspace sections #5771
Conversation
src/libs/actions/BankAccounts.js
Outdated
// one on the server side, let's make sure we use just the server-side data. | ||
if (hasLocalOpenAccount && lodashGet(achData, 'state', '') !== BankAccount.STATE.OPEN) { | ||
Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: false, error: ''}); | ||
reimbursementAccountInSetup = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we do Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: false, error: ''});
on line 348, it happens before reimbursementAccountInSetup
is set, so it never gets populated. In this case, we need to clear it manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think my first question is.... why are we using Onyx.set()
here and above instead of Onyx.merge()
? If there is no reason for it, then I think we should just use merge()
in both places and then I don't think you need any of the changes to the signature of fetchFreePlanVerifiedBankAccount()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just use merge() in both places
Correction: I mean, I think we can just use merge()
above, and that's the only change this PR needs to make.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use merge and the bank account has been deleted on the server side (but still remains in Onyx), it will remain in Oxyx instead of getting cleared out. Handling this situation was the annoying part of the issue 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How often would we expect that case to actually happen? Is that really a valid flow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't expect it to happen often at all. It can easily happen by deleting the bank account from oldDot, though.
Even not counting that flow, though I am not sure about using merge
all the time. This function is used in bank account setup and I worry using merge
in that flow will cause unwanted behavior (after all, the comments do mention we are using set
specifically and consciously.
If we don't worry about the deleted bank account situation, though, we could get rid of this part and just have the set/merge split at the top.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I saw the comment for the original set:
We are using set here since we will rely on data from the server (not local data) to populate the VBA flow
I don't know that this is really the desired behavior. This is making the app the opposite of offline-first. I think we should be fine rendering whatever is in Onyx, and then load new data on top of whatever is already there. Thinking about the setup flow, if the UI was showing what was in Onyx already, then why wouldn't it be OK to keep showing it when you're offline? I would try merge()
and just verify it doesn't change anything about the VBA flow.
Regarding the delete account flow, I spoke with you 1:1 to make sure I had the full context around that and I don't think it is a flow we should worry about right now because it's a very edge case. The proper solution for handling the bank account deletion is to implement a pusher event just like we do when a new action is added to a report.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. I have been doing some testing on the VBA flow with merge
and I haven't noticed any issues/differences. Let's move ahead with it, then!
|
I'm trying to think of a way we can do this without altering the logic in a flow that is mostly working OK. This change makes me a little uncomfortable as there may be other places that depend on the "reset" logic. |
Another way to look at this problem is that we are displaying options while we are still "loading" some information we need to determine which option to show. So, a safer move at this stage of the game might be to hold showing these option until loading is finished. |
You can take a look at my previous commit. You might like it better :) |
The solution I had in mind is to only render the children if we have
Otherwise we are passing |
I think this boils down to:
I think that almost everywhere else in the app we have decided that this is OK to do that. We show what's in Onyx, and then we update it silently in the background (think of the network reconnection logic). So, there isn't anything about this case which makes me think that we should treat it differently, but this is possibly where I am open to reason. |
Only thing I can add is that this feature was not implemented with that idea in mind and the interactions with local data and API are fairly complex in comparison to other simpler flows in the app. That's not to say we can't change how it works, but I think that's something that should have been established in the design stage. |
Did a quick test and found a couple of things that aren't working correctly. I'll continue testing and help find other issues if these are not decided to be blockers or we want to find solutions to them. Issue 1 - Unexpectedly dropped into the company step flow Repro steps:
Expected: Actual: Issue 2 - Error messages persist on page refresh Repro steps:
Expected: Actual: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the first issue found above. Maybe it's not a blocker if everything works OK? I only tested that the behavior changed. But I think the errors should clear if we are visiting a flow again so I would request we come up with a solution to that new problem introduced.
src/libs/actions/BankAccounts.js
Outdated
// We are using set here since we will rely on data from the server (not local data) to populate the VBA flow | ||
// and determine which step to navigate to. | ||
Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: true, error: ''}); | ||
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: true, error: ''}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinda want to propose a less risky change here. Here's how it goes...
Since the /bank-account
flow may be expecting multiple fields to be "reset" before we fetch the bank account then we should try to only carry over the state that we need for now.
I think to solve the current issue we could do something like:
const initialData = {loading: true, error: ''};
const state = lodashGet(reimbursementAccountInSetup, 'achData.state');
if (state === BankAccount.STATE.OPEN) {
initialData.achData = {state: BankAccount.STATE.OPEN};
}
Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT, initialData);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a pretty good solution, as it shouldn't affect the add bank account
flow, which was my main worry with the current one. However, it won't work as-is. At this point, reimbursementAccountInSetup is still empty, so there's no state there.
We can either pass a flag from WorspacePageWithSections
, as I was doing before, or do an Onyx.connect
. I think the first option might be better, but I can go for either. Any preference @marcaaron?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed changes for solution #1 (with the flag). LMK what you think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah bummer sounds like a good case for Onyx.isInitialized()
if it existed 😄
Do not always clear Onyx VBA data when accessing workspace sections (cherry picked from commit d61248f)
🚀 Cherry-picked to staging by @marcaaron in version: 1.1.7-7 🚀
@Expensify/applauseleads please QA this PR and check it off on the deploy checklist if it passes. |
🚀 Deployed to production by @AndrewGable in version: 1.1.7-24 🚀
|
🚀 Deployed to staging by @marcaaron in version: 1.1.7-25 🚀
|
🚀 Deployed to production by @roryabraham in version: 1.1.8-9 🚀
|
@MonilBhavsar, @tgolen
I'm not super happy with this solution, so I'm open to suggestions 😬
Fixed Issues
$ #5760
Tests/ QA Steps
Tested On