Skip to content

Commit 31f3e6d

Browse files
authored
Merge pull request Expensify#90485 from Expensify/revert-88458-feature/structural-sharing-cache-pr-4
[CP Staging] Revert "Bump Onyx to 3.0.71"
2 parents d631660 + 79175b5 commit 31f3e6d

4 files changed

Lines changed: 47 additions & 5 deletions

File tree

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
"react-native-localize": "^3.5.4",
180180
"react-native-nitro-modules": "0.35.0",
181181
"react-native-nitro-sqlite": "9.6.0",
182-
"react-native-onyx": "3.0.71",
182+
"react-native-onyx": "3.0.69",
183183
"react-native-pager-view": "8.0.0",
184184
"react-native-pdf": "7.0.2",
185185
"react-native-permissions": "^5.4.0",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# `react-native-onyx` patches
2+
3+
### [react-native-onyx+3.0.69.patch](react-native-onyx+3.0.69.patch)
4+
5+
- 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.
6+
- E/App issue: https://github.com/Expensify/App/issues/85416
7+
- Upstream PR/issue: N/A
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
diff --git a/node_modules/react-native-onyx/dist/useOnyx.js b/node_modules/react-native-onyx/dist/useOnyx.js
2+
index b361d0d..4df16fa 100644
3+
--- a/node_modules/react-native-onyx/dist/useOnyx.js
4+
+++ b/node_modules/react-native-onyx/dist/useOnyx.js
5+
@@ -97,6 +97,9 @@ function useOnyx(key, options, dependencies = []) {
6+
// after cleanup), so the hook automatically enters first-connection mode for the new key without any
7+
// explicit reset logic — eliminating the race condition where cleanup could clobber a boolean flag.
8+
const connectedKeyRef = (0, react_1.useRef)(null);
9+
+ // Tracks whether the hook has completed its initial mount subscription.
10+
+ // Unlike connectedKeyRef (which gets nulled by cleanup), this persists across re-subscriptions.
11+
+ const hasMountedRef = (0, react_1.useRef)(false);
12+
// Indicates if the hook is connecting to an Onyx key.
13+
const isConnectingRef = (0, react_1.useRef)(false);
14+
// Stores the `onStoreChange()` function, which can be used to trigger a `getSnapshot()` update when desired.
15+
@@ -220,11 +223,15 @@ function useOnyx(key, options, dependencies = []) {
16+
const subscribe = (0, react_1.useCallback)((onStoreChange) => {
17+
// Reset internal state so the hook properly transitions through loading
18+
// for the new key instead of preserving stale state from the previous one.
19+
- previousValueRef.current = null;
20+
- newValueRef.current = null;
21+
- shouldGetCachedValueRef.current = true;
22+
- sourceValueRef.current = undefined;
23+
- resultRef.current = [undefined, { status: (options === null || options === void 0 ? void 0 : options.initWithStoredValues) === false ? 'loaded' : 'loading' }];
24+
+ // Only reset when the key has actually changed (not on initial mount).
25+
+ if (hasMountedRef.current) {
26+
+ previousValueRef.current = null;
27+
+ newValueRef.current = null;
28+
+ shouldGetCachedValueRef.current = true;
29+
+ sourceValueRef.current = undefined;
30+
+ resultRef.current = [undefined, { status: (options === null || options === void 0 ? void 0 : options.initWithStoredValues) === false ? 'loaded' : 'loading' }];
31+
+ }
32+
+ hasMountedRef.current = true;
33+
isConnectingRef.current = true;
34+
onStoreChangeFnRef.current = onStoreChange;
35+
connectionRef.current = OnyxConnectionManager_1.default.connect({

0 commit comments

Comments
 (0)