@@ -344,22 +344,15 @@ class OnyxCache {
344344 iterResult = iterator . next ( ) ;
345345 }
346346
347- const affectedCollections = new Set < OnyxKey > ( ) ;
348-
349347 for ( const key of keysToRemove ) {
350348 delete this . storageMap [ key ] ;
351349
352- // Track affected collections for snapshot rebuild
353350 const collectionKey = OnyxKeys . getCollectionKey ( key ) ;
354351 if ( collectionKey ) {
355- affectedCollections . add ( collectionKey ) ;
352+ this . dirtyCollections . add ( collectionKey ) ;
356353 }
357354 this . recentKeys . delete ( key ) ;
358355 }
359-
360- for ( const collectionKey of affectedCollections ) {
361- this . dirtyCollections . add ( collectionKey ) ;
362- }
363356 }
364357
365358 /** Set the recent keys list size */
@@ -478,10 +471,10 @@ class OnyxCache {
478471 * @param collectionKey - The collection key to rebuild
479472 */
480473 private rebuildCollectionSnapshot ( collectionKey : OnyxKey ) : void {
481- const oldSnapshot = this . collectionSnapshots . get ( collectionKey ) ;
474+ const previousSnapshot = this . collectionSnapshots . get ( collectionKey ) ;
482475
483476 const members : NonUndefined < OnyxCollection < KeyValueMapping [ OnyxKey ] > > = { } ;
484- let hasChanges = false ;
477+ let hasMemberChanges = false ;
485478 let newMemberCount = 0 ;
486479
487480 // Use the indexed forward lookup for O(collectionMembers) iteration.
@@ -495,29 +488,31 @@ class OnyxCache {
495488 continue ;
496489 }
497490 const val = this . storageMap [ key ] ;
491+ // Skip null/undefined values — they represent deleted or unset keys
492+ // and should not be included in the frozen collection snapshot.
498493 if ( val !== undefined && val !== null ) {
499494 members [ key ] = val ;
500495 newMemberCount ++ ;
501496
502497 // Check if this member's reference changed from the old snapshot
503- if ( ! hasChanges && ( ! oldSnapshot || oldSnapshot [ key ] !== val ) ) {
504- hasChanges = true ;
498+ if ( ! hasMemberChanges && ( ! previousSnapshot || previousSnapshot [ key ] !== val ) ) {
499+ hasMemberChanges = true ;
505500 }
506501 }
507502 }
508503
509504 // Check if any members were removed (old snapshot had more keys)
510- if ( ! hasChanges && oldSnapshot ) {
511- const oldMemberCount = Object . keys ( oldSnapshot ) . length ;
505+ if ( ! hasMemberChanges && previousSnapshot ) {
506+ const oldMemberCount = Object . keys ( previousSnapshot ) . length ;
512507 if ( oldMemberCount !== newMemberCount ) {
513- hasChanges = true ;
508+ hasMemberChanges = true ;
514509 }
515510 }
516511
517512 // If nothing actually changed, reuse the old snapshot reference.
518513 // This is critical: useSyncExternalStore uses === to detect changes,
519514 // so returning the same reference prevents unnecessary re-renders.
520- if ( ! hasChanges && oldSnapshot ) {
515+ if ( ! hasMemberChanges && previousSnapshot ) {
521516 return ;
522517 }
523518
@@ -538,7 +533,7 @@ class OnyxCache {
538533 }
539534
540535 const snapshot = this . collectionSnapshots . get ( collectionKey ) ;
541- if ( ! snapshot || Object . keys ( snapshot ) . length === 0 ) {
536+ if ( utils . isEmptyObject ( snapshot ) ) {
542537 // If we know we have storage keys loaded, return a stable empty reference
543538 // to avoid new {} allocations that break useSyncExternalStore === equality.
544539 if ( this . storageKeys . size > 0 ) {
0 commit comments