Skip to content

Commit c1dbb9d

Browse files
committed
fix: add comment explaining storageKeys.size check in getCollectionData
1 parent 9a6fd30 commit c1dbb9d

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

lib/OnyxCache.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,11 @@ class OnyxCache {
534534

535535
const snapshot = this.collectionSnapshots.get(collectionKey);
536536
if (utils.isEmptyObject(snapshot)) {
537-
// If we know we have storage keys loaded, return a stable empty reference
538-
// to avoid new {} allocations that break useSyncExternalStore === equality.
537+
// We check storageKeys.size (not collection-specific keys) to distinguish
538+
// "init complete, this collection is genuinely empty" from "init not done yet."
539+
// During init, setAllKeys loads ALL keys at once — so if any key exists,
540+
// the full storage picture is loaded and an empty collection is truly empty.
541+
// Returning undefined before init prevents subscribers from seeing a false empty state.
539542
if (this.storageKeys.size > 0) {
540543
return FROZEN_EMPTY_COLLECTION;
541544
}

0 commit comments

Comments
 (0)