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 @@ -763,7 +763,7 @@ function shouldAssignObserverCurrentProperties<
763763) {
764764 // if the newly created result isn't what the observer is holding as current,
765765 // then we'll need to update the properties as well
766- if ( observer . getCurrentResult ( ) !== optimisticResult ) {
766+ if ( ! shallowEqualObjects ( observer . getCurrentResult ( ) , optimisticResult ) ) {
767767 return true
768768 }
769769
Original file line number Diff line number Diff line change @@ -6228,4 +6228,25 @@ describe('useQuery', () => {
62286228 await waitFor ( ( ) => rendered . getByText ( 'Rendered Id: 2' ) )
62296229 expect ( spy ) . toHaveBeenCalledTimes ( 1 )
62306230 } )
6231+ it ( 'should not cause an infinite render loop when using unstable callback ref' , async ( ) => {
6232+ const key = queryKey ( )
6233+
6234+ function Test ( ) {
6235+ const [ _ , setRef ] = React . useState < HTMLDivElement | null > ( )
6236+
6237+ const { data } = useQuery ( {
6238+ queryKey : [ key ] ,
6239+ queryFn : async ( ) => {
6240+ await sleep ( 5 )
6241+ return 'Works'
6242+ } ,
6243+ } )
6244+
6245+ return < div ref = { ( value ) => setRef ( value ) } > { data } </ div >
6246+ }
6247+
6248+ const rendered = renderWithClient ( queryClient , < Test /> )
6249+
6250+ await waitFor ( ( ) => rendered . getByText ( 'Works' ) )
6251+ } )
62316252} )
You can’t perform that action at this time.
0 commit comments