[Onyx Audit] Reset internal useOnyx state on key change#756
[Onyx Audit] Reset internal useOnyx state on key change#756JKobrynski wants to merge 2 commits intoExpensify:mainfrom
Conversation
…6-fix-useonyx-state-not-resetting
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8450987afc
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (key !== previousKey) { | ||
| previousValueRef.current = null; | ||
| newValueRef.current = null; | ||
| isFirstConnectionRef.current = true; | ||
| shouldGetCachedValueRef.current = true; |
There was a problem hiding this comment.
Keep the new key in first-connection mode until its callback arrives
Resetting previousValueRef and isFirstConnectionRef here interacts badly with the existing subscribe() cleanup. On a key change, the old subscription still cleans up and sets isFirstConnectionRef.current = false before the new Onyx.connect() callback fires. If anything rerenders the component in that window (for example a parent/context update while the new key is loading from storage), getSnapshot() takes its previousValueRef.current === null && !isFirstConnectionRef.current path and marks the new key as {status: 'loaded'} even though the initial callback for that key has not arrived yet.
Useful? React with 👍 / 👎.
|
Reviewing... |
Details
Related Issues
GH_LINK Expensify/App#85416
Automated Tests
Unit tests were added for the new logic.
Manual Tests
In all of the cases above look out for:
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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
web-compressed.mov