react-native-onyx 3.0.70 → 3.0.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/useOnyx.js +15 -4
- package/package.json +1 -1
package/dist/useOnyx.js
CHANGED
|
@@ -96,6 +96,9 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
96
96
|
// after cleanup), so the hook automatically enters first-connection mode for the new key without any
|
|
97
97
|
// explicit reset logic — eliminating the race condition where cleanup could clobber a boolean flag.
|
|
98
98
|
const connectedKeyRef = (0, react_1.useRef)(null);
|
|
99
|
+
// Tracks whether the hook has completed its initial mount subscription.
|
|
100
|
+
// Unlike connectedKeyRef (which gets nulled by cleanup), this persists across re-subscriptions.
|
|
101
|
+
const hasMountedRef = (0, react_1.useRef)(false);
|
|
99
102
|
// Indicates if the hook is connecting to an Onyx key.
|
|
100
103
|
const isConnectingRef = (0, react_1.useRef)(false);
|
|
101
104
|
// Stores the `onStoreChange()` function, which can be used to trigger a `getSnapshot()` update when desired.
|
|
@@ -211,11 +214,19 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
211
214
|
const subscribe = (0, react_1.useCallback)((onStoreChange) => {
|
|
212
215
|
// Reset internal state so the hook properly transitions through loading
|
|
213
216
|
// for the new key instead of preserving stale state from the previous one.
|
|
214
|
-
|
|
215
|
-
|
|
217
|
+
// Only reset when the key has actually changed (not on initial mount).
|
|
218
|
+
if (hasMountedRef.current) {
|
|
219
|
+
previousValueRef.current = null;
|
|
220
|
+
newValueRef.current = null;
|
|
221
|
+
sourceValueRef.current = undefined;
|
|
222
|
+
resultRef.current = [undefined, { status: (options === null || options === void 0 ? void 0 : options.initWithStoredValues) === false ? 'loaded' : 'loading' }];
|
|
223
|
+
}
|
|
224
|
+
// Force a cache re-read on every (re)subscription so any side effects from
|
|
225
|
+
// subscribeToKey (e.g. addNullishStorageKey for skippable collection member ids)
|
|
226
|
+
// are reflected in the next getSnapshot. Resetting this flag does not change
|
|
227
|
+
// resultRef by itself, so it doesn't cause an extra mount render.
|
|
216
228
|
shouldGetCachedValueRef.current = true;
|
|
217
|
-
|
|
218
|
-
resultRef.current = [undefined, { status: (options === null || options === void 0 ? void 0 : options.initWithStoredValues) === false ? 'loaded' : 'loading' }];
|
|
229
|
+
hasMountedRef.current = true;
|
|
219
230
|
isConnectingRef.current = true;
|
|
220
231
|
onStoreChangeFnRef.current = onStoreChange;
|
|
221
232
|
connectionRef.current = OnyxConnectionManager_1.default.connect({
|