Skip to content

Commit 0f8a352

Browse files
committed
remove allowDynamicKey support
1 parent 29b7061 commit 0f8a352

3 files changed

Lines changed: 40 additions & 32 deletions

File tree

lib/OnyxSnapshotCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class OnyxSnapshotCache {
6060
* - `selector`: Different selectors produce different results, so each selector needs its own cache entry
6161
* - `initWithStoredValues`: This flag changes the initial loading behavior and affects the returned fetch status
6262
*
63-
* Other options like `canEvict`, `reuseConnection`, and `allowDynamicKey` don't affect the data transformation
63+
* Other options like `canEvict` and `reuseConnection` don't affect the data transformation
6464
* or timing behavior of getSnapshot, so they're excluded from the cache key for better cache hit rates.
6565
*/
6666
registerConsumer<TKey extends OnyxKey, TReturnValue>(options: Pick<UseOnyxOptions<TKey, TReturnValue>, 'selector' | 'initWithStoredValues'>): string {

lib/useOnyx.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import usePrevious from './usePrevious';
1111
import decorateWithMetrics from './metrics';
1212
import onyxSnapshotCache from './OnyxSnapshotCache';
1313
import useLiveRef from './useLiveRef';
14+
import * as Logger from './Logger';
1415

1516
type UseOnyxSelector<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>> = (data: OnyxValue<TKey> | undefined) => TReturnValue;
1617

@@ -32,11 +33,6 @@ type UseOnyxOptions<TKey extends OnyxKey, TReturnValue> = {
3233
*/
3334
reuseConnection?: boolean;
3435

35-
/**
36-
* If set to `true`, the key can be changed dynamically during the component lifecycle.
37-
*/
38-
allowDynamicKey?: boolean;
39-
4036
/**
4137
* This will be used to subscribe to a subset of an Onyx key's data.
4238
* Using this setting on `useOnyx` can have very positive performance benefits because the component will only re-render
@@ -148,8 +144,7 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
148144
useEffect(() => () => onyxSnapshotCache.deregisterConsumer(key, cacheKey), [key, cacheKey]);
149145

150146
useEffect(() => {
151-
// These conditions will ensure we can only handle dynamic collection member keys from the same collection.
152-
if (options?.allowDynamicKey || previousKey === key) {
147+
if (previousKey === key) {
153148
return;
154149
}
155150

@@ -166,10 +161,10 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
166161
);
167162
}
168163

169-
throw new Error(
170-
`'${previousKey}' key can't be changed to '${key}'. useOnyx() only supports dynamic keys if they are both collection member keys from the same collection e.g. from 'collection_id1' to 'collection_id2'.`,
171-
);
172-
}, [previousKey, key, options?.allowDynamicKey]);
164+
if (process.env.NODE_ENV === 'development') {
165+
Logger.logAlert(`useOnyx: key changed from '${previousKey}' to '${key}' across collections.`);
166+
}
167+
}, [previousKey, key]);
173168

174169
// Track previous dependencies to prevent infinite loops
175170
const previousDependenciesRef = useRef<DependencyList>([]);

0 commit comments

Comments
 (0)