File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed
Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -236,6 +236,13 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
236236 if ( ! ( isFirstConnectionRef . current && options ?. initWithStoredValues === false ) && ! shouldGetCachedValueRef . current ) {
237237 const cachedResult = onyxSnapshotCache . getCachedResult < UseOnyxResult < TReturnValue > > ( key , cacheKey ) ;
238238 if ( cachedResult !== undefined ) {
239+ // Collections are rebuilt as new objects each time via getCollectionData, so we need to compare values
240+ // and preserve reference stability to prevent unnecessary rerenders
241+ const isCollection = OnyxUtils . isCollectionKey ( key ) ;
242+ if ( isCollection && deepEqual ( cachedResult , resultRef . current ) ) {
243+ return resultRef . current ;
244+ }
245+
239246 resultRef . current = cachedResult ;
240247 return cachedResult ;
241248 }
You can’t perform that action at this time.
0 commit comments