Skip to content

Commit 44644a3

Browse files
authored
Merge pull request #791 from nkdengineer/fix/89800
fix: generate unique cache key for different keys
2 parents b506f32 + fb5655d commit 44644a3

5 files changed

Lines changed: 65 additions & 44 deletions

File tree

lib/OnyxSnapshotCache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ class OnyxSnapshotCache {
6262
* Other options like `reuseConnection` don't affect the data transformation
6363
* or timing behavior of getSnapshot, so they're excluded from the cache key for better cache hit rates.
6464
*/
65-
registerConsumer<TKey extends OnyxKey, TReturnValue>(options: Pick<UseOnyxOptions<TKey, TReturnValue>, 'selector'>): string {
65+
registerConsumer<TKey extends OnyxKey, TReturnValue>(key: TKey, options: Pick<UseOnyxOptions<TKey, TReturnValue>, 'selector'>): string {
6666
const selectorID = options?.selector ? this.getSelectorID(options.selector) : 'no_selector';
67-
const cacheKey = String(selectorID);
67+
const cacheKey = `${key}_${selectorID}`;
6868

6969
// Increment reference count for this cache key
7070
const currentCount = this.cacheKeyRefCounts.get(cacheKey) || 0;

lib/useOnyx.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
124124
// Cache the options key to avoid regenerating it every getSnapshot call
125125
const cacheKey = useMemo(
126126
() =>
127-
onyxSnapshotCache.registerConsumer({
127+
onyxSnapshotCache.registerConsumer(key, {
128128
selector: options?.selector,
129129
}),
130-
[options?.selector],
130+
[key, options?.selector],
131131
);
132132

133133
useEffect(() => () => onyxSnapshotCache.deregisterConsumer(key, cacheKey), [key, cacheKey]);

0 commit comments

Comments
 (0)