File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
react-query/src/__tests__ Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -834,7 +834,7 @@ function shouldAssignObserverCurrentProperties<
834
834
835
835
// if the newly created result isn't what the observer is holding as current,
836
836
// then we'll need to update the properties as well
837
- if ( observer . getCurrentResult ( ) !== optimisticResult ) {
837
+ if ( ! shallowEqualObjects ( observer . getCurrentResult ( ) , optimisticResult ) ) {
838
838
return true
839
839
}
840
840
Original file line number Diff line number Diff line change @@ -6211,4 +6211,25 @@ describe('useQuery', () => {
6211
6211
await waitFor ( ( ) => rendered . getByText ( 'Rendered Id: 2' ) )
6212
6212
expect ( spy ) . toHaveBeenCalledTimes ( 1 )
6213
6213
} )
6214
+ it ( 'should not cause an infinite render loop when using unstable callback ref' , async ( ) => {
6215
+ const key = queryKey ( )
6216
+
6217
+ function Test ( ) {
6218
+ const [ _ , setRef ] = React . useState < HTMLDivElement | null > ( )
6219
+
6220
+ const { data } = useQuery ( {
6221
+ queryKey : [ key ] ,
6222
+ queryFn : async ( ) => {
6223
+ await sleep ( 5 )
6224
+ return 'Works'
6225
+ } ,
6226
+ } )
6227
+
6228
+ return < div ref = { ( value ) => setRef ( value ) } > { data } </ div >
6229
+ }
6230
+
6231
+ const rendered = renderWithClient ( queryClient , < Test /> )
6232
+
6233
+ await waitFor ( ( ) => rendered . getByText ( 'Works' ) )
6234
+ } )
6214
6235
} )
You can’t perform that action at this time.
0 commit comments