Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
"react-native-localize": "^3.5.4",
"react-native-nitro-modules": "0.29.4",
"react-native-nitro-sqlite": "9.2.0",
"react-native-onyx": "3.0.58",
"react-native-onyx": "3.0.59",
"react-native-pager-view": "8.0.0",
"react-native-pdf": "7.0.2",
"react-native-permissions": "^5.4.0",
Expand Down
7 changes: 7 additions & 0 deletions patches/react-native-onyx/details.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# `react-native-onyx` patches

### [react-native-onyx+3.0.59.patch](react-native-onyx+3.0.59.patch)

- Reason: Onyx v3.0.59 ([PR #756](https://github.com/Expensify/react-native-onyx/pull/756)) added a state reset inside the `subscribe` callback of `useOnyx` to fix stale data when keys change dynamically. However, this reset runs unconditionally — including on initial mount — which causes `useSyncExternalStore` to see a new snapshot reference after subscription, triggering one extra render per `useOnyx` hook. This patch guards the reset with a `hasMountedRef` flag so it only runs on key-change re-subscriptions, not on initial mount.
- E/App issue: https://github.com/Expensify/App/issues/85416
- Upstream PR/issue: N/A
35 changes: 35 additions & 0 deletions patches/react-native-onyx/react-native-onyx+3.0.59.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
diff --git a/node_modules/react-native-onyx/dist/useOnyx.js b/node_modules/react-native-onyx/dist/useOnyx.js
index 8e0f03a..9e29ace 100644
--- a/node_modules/react-native-onyx/dist/useOnyx.js
+++ b/node_modules/react-native-onyx/dist/useOnyx.js
@@ -97,6 +97,9 @@ function useOnyx(key, options, dependencies = []) {
// after cleanup), so the hook automatically enters first-connection mode for the new key without any
// explicit reset logic — eliminating the race condition where cleanup could clobber a boolean flag.
const connectedKeyRef = (0, react_1.useRef)(null);
+ // Tracks whether the hook has completed its initial mount subscription.
+ // Unlike connectedKeyRef (which gets nulled by cleanup), this persists across re-subscriptions.
+ const hasMountedRef = (0, react_1.useRef)(false);
// Indicates if the hook is connecting to an Onyx key.
const isConnectingRef = (0, react_1.useRef)(false);
// Stores the `onStoreChange()` function, which can be used to trigger a `getSnapshot()` update when desired.
@@ -234,11 +237,15 @@ function useOnyx(key, options, dependencies = []) {
const subscribe = (0, react_1.useCallback)((onStoreChange) => {
// Reset internal state so the hook properly transitions through loading
// for the new key instead of preserving stale state from the previous one.
- previousValueRef.current = null;
- newValueRef.current = null;
- shouldGetCachedValueRef.current = true;
- sourceValueRef.current = undefined;
- resultRef.current = [undefined, { status: (options === null || options === void 0 ? void 0 : options.initWithStoredValues) === false ? 'loaded' : 'loading' }];
+ // Only reset when the key has actually changed (not on initial mount).
+ if (hasMountedRef.current) {
+ previousValueRef.current = null;
+ newValueRef.current = null;
+ shouldGetCachedValueRef.current = true;
+ sourceValueRef.current = undefined;
+ resultRef.current = [undefined, { status: (options === null || options === void 0 ? void 0 : options.initWithStoredValues) === false ? 'loaded' : 'loading' }];
+ }
+ hasMountedRef.current = true;
isConnectingRef.current = true;
onStoreChangeFnRef.current = onStoreChange;
connectionRef.current = OnyxConnectionManager_1.default.connect({
Loading