Repository navigation
[On HOLD till related app cleanups pass staging testing] Remove per-key loading status from useOnyx - #904
Draft
VickyStash wants to merge 4 commits into
Conversation
9 tasks
# Conflicts: # lib/useOnyx.ts
38 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details
useOnyxreturns[value, {status}]. Until now,statuswasloadingin two cases:Onyx.inithas loaded storage into the cache.Onyx.mergeto it is pending. This lasts until the merge lands, usually one microtask.To support case 2, every
useOnyxcall kept a second key subscription plus a ref and an effect. The E/App no longer reads the per-key status: theno-onyx-loading-statuslint rule blocks new reads, and the remaining readers only wait forOnyx.init. This PR removes case 2 and keeps the startup status.Changes in
lib/useOnyx.ts:connectedKeyRefwith its effect, andAVAILABILITY/getAvailability.useSyncExternalStoreonOnyx.init, built onOnyxUtils.scheduleHydrationNotificationlike inuseOnyxState. It re-renders a hook that mounted before init once init finishes, and adds no listener after that. The key subscription no longer needs its own init notification.With this change,
statusisloadinguntilOnyx.initfinishes andloadedfrom then on. A hook that mounts on an empty key during a pending merge now getsundefinedwithloaded, then the merged value. Before, it gotloadingin between.The types and the
[value, {status}]shape stay the same.Related Issues
Expensify/App#104583
Linked E/App PR
Expensify/App#108890
Automated Tests
Updated
tests/unit/useOnyxTest.ts.Manual Tests
Startup with data in storage
Startup with an empty cache
Sign out and in
General
Author Checklist
### Related Issuessection above### Linked E/App PRsection above, and verified this change against it (E/App CI passed and manual testing completed)TestssectiontoggleReportand 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