-
Notifications
You must be signed in to change notification settings - Fork 73
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: state management flow to avoid data loss #283
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
69a49b0
to
f8cd766
Compare
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.
@pasyukevich can you add some manual test cases to the PR description, please? So reviewers know how to verify the fix.
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.
@Julesssss could you provide details on how you managed to reproduce the issue? I will take a look |
Yeah, so internally we use Ngrok for dev testing. A lot of us have noticed that NewDot is bricked on Android emulators with the chrome app: Expensify/App#22122 But perhaps that is a separate issue after all... oh well. We still need some tests that we can use to verify this fix though. |
@Julesssss I'm in the process of preparing the instruction to verify the fix. However, it has become more challenging to do so with my previous flow, after updating to the latest version of the app. Now, I'm observing that in most instances, 'setState' is not invoked before 'setWithOnyxState' when using the same input. When it comes to testing it locally, I've simply modified 'withOnyx.js' and 'web.development.js' inside the node_modules by incorporating this fix for both the mobile and web platforms. |
Hi @Julesssss I'm not able to reproduce the issue on the latest app version, so I prepared steps on how to reproduce it on the old app but with the latest Onyx library Step-by-step on how to reproduce the broken flow for Onyx
|
@pasyukevich can you please clarify exactly what issue existed before this change and fixed after this change? |
@aimane-chnaif Sure This change should fix the flow when the Onyx variable is not updated to the latest
|
This PR has stalled for a couple of weeks. Can we keep it moving @aimane-chnaif? |
yes, sure. sorry for delay |
@pasyukevich please fix conflict |
f8cd766
to
5dc9847
Compare
@aimane-chnaif PR is updated |
I see that the update was applied to the Onyx library that was aimed to fix the same problem, but during my test, it did not work well in the described flow With this branch after cleaning node modules and reinstalling them I was able to reproduce the composer issue. - Expensify/App#21881 I found that the approach with function in the setState fixes this issue, but the manual assign is not (as it is now done in the wIthOnyx) |
I will test after Expensify/App#24041 (which bumps this repo version) is merged in E/App. |
@aimane-chnaif this flow is not reproducible on the current app version due to the page commits best choice is to use this branch of app with updated Onyx library version I can prepare an updated branch and flow with newer Onyx and recheck |
Sure, thanks! |
I created a new test branch with updated Onyx test-report-expanded-latest-onyx Instruction updated - #283 (comment) This behavior is still reproducible |
@hannojg @Szymon20000 Could you help review this PR and issue its attempting to solve, your experience with Onyx might be handy, thanks! |
lib/withOnyx.js
Outdated
this.setState(stateUpdate); // Trigger a render | ||
// Retain previous state to avoid data loss during pre-load updates. | ||
// This handles race conditions where setWithOnyxState might be called after setState | ||
this.setState(prevState => ({...this.tempState, ...prevState, loading: false})); |
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.
What is the race condition exactly? Is there any example? Can we break this problem down a bit further in the comment? Who is calling setState()
and why should we ever prefer the previous state of the withOnyx()
component over the initial value being set here?
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.
Comment updated
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.
Exact flow described here
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.
That's pretty interesting.
So ultimately, sounds like we have made the bad assumption here that setState()
can never be called before setWithOnyxState()
.
If we got here and the state
already has the key then we could
in theory remove it from tempState
? That approach might be a little more obvious vs. spreading the prevState
after the tempState
. Though they would achieve the same result. Thoughts?
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 agree with you that it would be more straightforward to remove properties from the tempState
that already exist in prevState
I'd assume that you mean something like omit
I will recheck the flow again with the update and apply changes
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.
@marcaaron PR updated with omit approach
5dc9847
to
222b0dd
Compare
Signed-off-by: Yauheni Pasiukevich <pasyukevich@live.com>
222b0dd
to
8af5aaf
Compare
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.
LGTM thanks for the change
All yours @Julesssss ! |
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.
Okay, we'll have to be careful to test this in the App PR that bumps the Onyx lib.
I will be taking responsible for this |
Sweet. I created a bump PR here but I'm struggling to build Desktop now... |
Actually, the Desktop error seems unrelated |
Details
Related Issues
Expensify/App#22122
Expensify/App#21881
Automated Tests
Linked PRs