[POC] useOnyx subscribed#808
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9e6e74e41e
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9b8bcea76e
ℹ️ 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".
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 52c7e8f3ce
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e12bd8663b
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 13f825e360
ℹ️ 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".
| useEffect(() => { | ||
| subscribedRef.current = subscribed; | ||
| }, [subscribed]); |
There was a problem hiding this comment.
Keep the subscribed ref current before effects
When subscribed flips from false to true, this ref is not updated until the passive effect runs, but the Onyx callback can fire in the gap after the focused render commits and before effects flush (for example from a layout effect or another synchronous Onyx write during navigation focus). In that window the callback still sees false, suppresses onStoreChange(), and the now-visible subscriber can miss the update until some unrelated render occurs.
Useful? React with 👍 / 👎.
Details
useOnyxnow accepts asubscribedoption (defaults totrue)When
subscribedisfalse, the hook keeps its Onyx connection open (so thevalue stays cache-warm) but stops re-rendering the component on background
writes to that key. It defers the render trigger, not the value: any render
from another cause still reads the latest value via
getSnapshot(), and flippingsubscribedback totrue(e.g. on re-focus) re-renders with the newest value.Why
Out-of-focus screens re-render every time their underlying data churns, even when
nothing is on screen. That's wasted work.
subscribed: falselets a screen pauseits render reactions while staying connected, then catch up instantly when it
matters again, without paying the connect/disconnect cost of tearing the
subscription down and rebuilding it.
Why this implementation
onStoreChange()behind a ref, don't re-subscribe. The connectcallback reads
subscribedRef.currentand simply skipsonStoreChange()whilepaused. Toggling
subscribednever re-subscribes, so we avoid the connect/resetchurn a subscribe-dependency approach would cause. The ref is kept current by a
small effect.
is the subtle part: the value must not go stale. Because we keep invalidating and
set
shouldGetCachedValueRef, the next render from any cause serves the freshvalue instead of a cached-stale one.
subscribeddefaults totrue, so existing consumersbehave exactly as before. Verified by perf tests (identical render counts) and
a dedicated default-path test.
Related Issues
GH_LINK
Linked E/App PR
Automated Tests
Manual Tests
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