Skip to content

Commit b735ed4

Browse files
authored
Merge pull request Expensify#90764 from callstack-internal/feature/bump-onyx-to-3.0.71-v2
Bump Onyx to 3.0.71 [v2]
2 parents 307959e + 0033d74 commit b735ed4

5 files changed

Lines changed: 80 additions & 44 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.69",
182+
"react-native-onyx": "3.0.71",
183183
"react-native-pager-view": "8.0.0",
184184
"react-native-pdf": "7.0.2",
185185
"react-native-permissions": "^5.4.0",
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# `react-native-onyx` patches
22

3-
### [react-native-onyx+3.0.69.patch](react-native-onyx+3.0.69.patch)
3+
### [react-native-onyx+3.0.71.patch](react-native-onyx+3.0.71.patch)
44

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
5+
- Reason:
6+
7+
> Reverts [Onyx PR #770 (the subscription-side skip for skippable collection member ids in subscribeToKey)](https://github.com/Expensify/react-native-onyx/pull/770) and the line [PR #779](https://github.com/Expensify/react-native-onyx/pull/779) added to work around [PR #770](https://github.com/Expensify/react-native-onyx/pull/770)'s silent-no-callback contract.
8+
9+
- Upstream PR/issue: https://github.com/Expensify/react-native-onyx/pull/785
10+
- E/App issue: https://github.com/Expensify/App/issues/86181
11+
- PR Introducing Patch: https://github.com/Expensify/App/pull/90764

patches/react-native-onyx/react-native-onyx+3.0.69.patch

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
diff --git a/node_modules/react-native-onyx/dist/OnyxUtils.js b/node_modules/react-native-onyx/dist/OnyxUtils.js
2+
index de56f94..495d378 100644
3+
--- a/node_modules/react-native-onyx/dist/OnyxUtils.js
4+
+++ b/node_modules/react-native-onyx/dist/OnyxUtils.js
5+
@@ -868,24 +868,6 @@ function subscribeToKey(connectOptions) {
6+
const subscriptionID = lastSubscriptionID++;
7+
callbackToStateMapping[subscriptionID] = mapping;
8+
callbackToStateMapping[subscriptionID].subscriptionID = subscriptionID;
9+
- // If the subscriber is attempting to connect to a collection member whose ID is skippable (e.g. "undefined", "null", etc.)
10+
- // we suppress wiring the subscription fully to avoid unnecessary callback emissions such as for "report_undefined".
11+
- // We still return a valid subscriptionID so callers can disconnect safely.
12+
- try {
13+
- const skippableIDs = getSkippableCollectionMemberIDs();
14+
- if (skippableIDs.size) {
15+
- const [, collectionMemberID] = OnyxKeys_1.default.splitCollectionMemberKey(mapping.key);
16+
- if (skippableIDs.has(collectionMemberID)) {
17+
- // Clean up the provisional mapping to avoid retaining unused subscribers.
18+
- OnyxCache_1.default.addNullishStorageKey(mapping.key);
19+
- delete callbackToStateMapping[subscriptionID];
20+
- return subscriptionID;
21+
- }
22+
- }
23+
- }
24+
- catch (e) {
25+
- // Not a collection member key, proceed as usual.
26+
- }
27+
// When keyChanged is called, a key is passed and the method looks through all the Subscribers in callbackToStateMapping for the matching key to get the subscriptionID
28+
// to avoid having to loop through all the Subscribers all the time (even when just one connection belongs to one key),
29+
// We create a mapping from key to lists of subscriptionIDs to access the specific list of subscriptionIDs.
30+
@@ -1394,12 +1376,6 @@ function logKeyChanged(onyxMethod, key, value, hasChanged) {
31+
function logKeyRemoved(onyxMethod, key) {
32+
Logger.logInfo(`${onyxMethod} called for key: ${key} => null passed, so key was removed`);
33+
}
34+
-/**
35+
- * Getter - returns the callback to state mapping, useful in test environments.
36+
- */
37+
-function getCallbackToStateMapping() {
38+
- return callbackToStateMapping;
39+
-}
40+
/**
41+
* Clear internal variables used in this file, useful in test environments.
42+
*/
43+
@@ -1458,6 +1434,5 @@ const OnyxUtils = {
44+
setWithRetry,
45+
multiSetWithRetry,
46+
setCollectionWithRetry,
47+
- getCallbackToStateMapping,
48+
};
49+
exports.default = OnyxUtils;
50+
diff --git a/node_modules/react-native-onyx/dist/useOnyx.js b/node_modules/react-native-onyx/dist/useOnyx.js
51+
index 9213cff..2e48c73 100644
52+
--- a/node_modules/react-native-onyx/dist/useOnyx.js
53+
+++ b/node_modules/react-native-onyx/dist/useOnyx.js
54+
@@ -220,12 +220,8 @@ function useOnyx(key, options, dependencies = []) {
55+
newValueRef.current = null;
56+
sourceValueRef.current = undefined;
57+
resultRef.current = [undefined, { status: (options === null || options === void 0 ? void 0 : options.initWithStoredValues) === false ? 'loaded' : 'loading' }];
58+
+ shouldGetCachedValueRef.current = true;
59+
}
60+
- // Force a cache re-read on every (re)subscription so any side effects from
61+
- // subscribeToKey (e.g. addNullishStorageKey for skippable collection member ids)
62+
- // are reflected in the next getSnapshot. Resetting this flag does not change
63+
- // resultRef by itself, so it doesn't cause an extra mount render.
64+
- shouldGetCachedValueRef.current = true;
65+
hasMountedRef.current = true;
66+
isConnectingRef.current = true;
67+
onStoreChangeFnRef.current = onStoreChange;

0 commit comments

Comments
 (0)