Skip to content

Commit f1e1ba1

Browse files
committed
fix: remove cachedCollection mutation in keyChanged that silently fails on frozen snapshots
1 parent dcceeeb commit f1e1ba1

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

lib/OnyxUtils.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,6 @@ function keyChanged<TKey extends OnyxKey>(
640640
}
641641
}
642642

643-
const cachedCollections: Record<string, ReturnType<typeof getCachedCollection>> = {};
644-
645643
for (const stateMappingKey of stateMappingKeys) {
646644
const subscriber = callbackToStateMapping[stateMappingKey];
647645
if (!subscriber || !OnyxKeys.isKeyMatch(subscriber.key, key) || !canUpdateSubscriber(subscriber)) {
@@ -662,14 +660,9 @@ function keyChanged<TKey extends OnyxKey>(
662660
if (isProcessingCollectionUpdate) {
663661
continue;
664662
}
665-
let cachedCollection = cachedCollections[subscriber.key];
666-
667-
if (!cachedCollection) {
668-
cachedCollection = getCachedCollection(subscriber.key);
669-
cachedCollections[subscriber.key] = cachedCollection;
670-
}
671-
672-
cachedCollection[key] = value;
663+
// The cache is always updated before keyChanged runs (via broadcastUpdate → cache.set),
664+
// so the frozen snapshot already contains the new value — no patching needed.
665+
const cachedCollection = getCachedCollection(subscriber.key);
673666
lastConnectionCallbackData.set(subscriber.subscriptionID, {value: cachedCollection, matchedKey: subscriber.key});
674667
subscriber.callback(cachedCollection, subscriber.key, {[key]: value});
675668
continue;

0 commit comments

Comments
 (0)