@@ -475,7 +475,6 @@ class OnyxCache {
475475
476476 const members : NonUndefined < OnyxCollection < KeyValueMapping [ OnyxKey ] > > = { } ;
477477 let hasMemberChanges = false ;
478- let newMemberCount = 0 ;
479478
480479 // Use the indexed forward lookup for O(collectionMembers) iteration.
481480 // Falls back to scanning all storageKeys if the index isn't populated yet.
@@ -492,7 +491,6 @@ class OnyxCache {
492491 // and should not be included in the frozen collection snapshot.
493492 if ( val !== undefined && val !== null ) {
494493 members [ key ] = val ;
495- newMemberCount ++ ;
496494
497495 // Check if this member's reference changed from the old snapshot
498496 if ( ! hasMemberChanges && ( ! previousSnapshot || previousSnapshot [ key ] !== val ) ) {
@@ -501,11 +499,16 @@ class OnyxCache {
501499 }
502500 }
503501
504- // Check if any members were removed (old snapshot had more keys)
502+ // Check if any members were removed from the previous snapshot.
503+ // We can't rely on count comparison alone — if one key is removed and another added,
504+ // the counts match but the snapshot content is different.
505505 if ( ! hasMemberChanges && previousSnapshot ) {
506- const oldMemberCount = Object . keys ( previousSnapshot ) . length ;
507- if ( oldMemberCount !== newMemberCount ) {
508- hasMemberChanges = true ;
506+ // eslint-disable-next-line no-restricted-syntax
507+ for ( const key in previousSnapshot ) {
508+ if ( ! ( key in members ) ) {
509+ hasMemberChanges = true ;
510+ break ;
511+ }
509512 }
510513 }
511514
0 commit comments