@@ -394,8 +394,8 @@ function isCollectionKey(key: OnyxKey): key is CollectionKeyBase {
394394 return onyxCollectionKeySet . has ( key ) ;
395395}
396396
397- function isCollectionMemberKey < TCollectionKey extends CollectionKeyBase > ( collectionKey : TCollectionKey , key : string ) : key is `${TCollectionKey } ${string } ` {
398- return key . startsWith ( collectionKey ) && key . length > collectionKey . length ;
397+ function isCollectionMemberKey < TCollectionKey extends CollectionKeyBase > ( collectionKey : TCollectionKey , key : string , collectionKeyLength : number ) : key is `${TCollectionKey } ${string } ` {
398+ return Str . startsWith ( key , collectionKey ) && key . length > collectionKeyLength ;
399399}
400400
401401/**
@@ -554,12 +554,14 @@ function getCachedCollection<TKey extends CollectionKeyBase>(collectionKey: TKey
554554 const allKeys = collectionMemberKeys || cache . getAllKeys ( ) ;
555555 const collection : OnyxCollection < KeyValueMapping [ TKey ] > = { } ;
556556
557+ const collectionKeyLength = collectionKey . length ;
558+
557559 // forEach exists on both Set and Array
558560 allKeys . forEach ( ( key ) => {
559561 // If we don't have collectionMemberKeys array then we have to check whether a key is a collection member key.
560562 // Because in that case the keys will be coming from `cache.getAllKeys()` and we need to filter out the keys that
561563 // are not part of the collection.
562- if ( ! collectionMemberKeys && ! isCollectionMemberKey ( collectionKey , key ) ) {
564+ if ( ! collectionMemberKeys && ! isCollectionMemberKey ( collectionKey , key , collectionKeyLength ) ) {
563565 return ;
564566 }
565567
@@ -595,6 +597,7 @@ function keysChanged<TKey extends CollectionKeyBase>(
595597 // individual collection key member for the collection that is being updated. It is important to note that the collection parameter cane be a PARTIAL collection
596598 // and does not represent all of the combined keys and values for a collection key. It is just the "new" data that was merged in via mergeCollection().
597599 const stateMappingKeys = Object . keys ( callbackToStateMapping ) ;
600+ const collectionKeyLength = collectionKey . length ;
598601 for ( let i = 0 ; i < stateMappingKeys . length ; i ++ ) {
599602 const subscriber = callbackToStateMapping [ stateMappingKeys [ i ] ] ;
600603 if ( ! subscriber ) {
@@ -614,7 +617,7 @@ function keysChanged<TKey extends CollectionKeyBase>(
614617 /**
615618 * e.g. Onyx.connect({key: `${ONYXKEYS.COLLECTION.REPORT}{reportID}`, callback: ...});
616619 */
617- const isSubscribedToCollectionMemberKey = isCollectionMemberKey ( collectionKey , subscriber . key ) ;
620+ const isSubscribedToCollectionMemberKey = isCollectionMemberKey ( collectionKey , subscriber . key , collectionKeyLength ) ;
618621
619622 // Regular Onyx.connect() subscriber found.
620623 if ( typeof subscriber . callback === 'function' ) {
0 commit comments