-
Notifications
You must be signed in to change notification settings - Fork 86
fix: result isn't changed when the member collection change v2 #716
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
base: main
Are you sure you want to change the base?
Conversation
deetergp
left a comment
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.
👍
|
Actually, this looks like @cead22 & @eVoloshchak should be reviewing this one. Adding them… |
cead22
left a comment
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.
This change doesn't look like the approved proposal in the linked issue, what's the reason?
| } | ||
|
|
||
| // We get the value from cache while the first connection to Onyx is being made, | ||
| // We get the value from cache while the first connection to Onyx is being made or the key has changed, |
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.
Why do we return the cached value if the key has changed? Can we include the reason in this comment?
| // We get the value from cache while the first connection to Onyx is being made or the key has changed, | |
| // We get the value from cache while the first connection to Onyx is being made or if the key has changed, |
|
@tgolen can you please take a look at this change? |
tgolen
left a comment
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.
Any changes here need to be covered by a unit test.
| // so we can return any cached value right away. After the connection is made, we only | ||
| // update `newValueRef` when `Onyx.connect()` callback is fired. | ||
| if (isFirstConnectionRef.current || shouldGetCachedValueRef.current) { | ||
| if (isFirstConnectionRef.current || shouldGetCachedValueRef.current || key !== previousKey) { |
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.
It feels like there are already a handful of options that should help the original issue, without making this change. useOnyx() has options for:
- initWithStoredValues
- allowStaleData
- allowDynamicKey
- selectors with a dependency array
Wouldn't there be some combination of those that would fix the original problem in the issue?
Details
When the key from
useOnyxis changed, the previousKey's value is returned because we don't updatenewValueRef.currentuntil theOnyx.connect()is fired. This PR updates thegetSnapshotfunction to get the value from cache immediately when the key is changed.Related Issues
Expensify/App#76015
Automated Tests
Manual Tests
Precondition:
Author Checklist
### Related Issuessection aboveTestssectiontoggleReportand notonIconClick)myBool && <MyComponent />.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)Avataris modified, I verified thatAvataris working as expected in all cases)mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Screen.Recording.2025-12-07.at.21.19.45.mov
Android: mWeb Chrome
Screen.Recording.2025-12-07.at.21.18.40.mov
iOS: Native
Screen.Recording.2025-12-07.at.21.23.22.mov
iOS: mWeb Safari
Screen.Recording.2025-12-07.at.21.21.19.mov
MacOS: Chrome / Safari
Screen.Recording.2025-12-07.at.21.17.33.mov