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<
834834
835835 // if the newly created result isn't what the observer is holding as current,
836836 // then we'll need to update the properties as well
837- if ( observer . getCurrentResult ( ) !== optimisticResult ) {
837+ if ( ! shallowEqualObjects ( observer . getCurrentResult ( ) , optimisticResult ) ) {
838838 return true
839839 }
840840
Original file line number Diff line number Diff line change @@ -6211,4 +6211,25 @@ describe('useQuery', () => {
62116211 await waitFor ( ( ) => rendered . getByText ( 'Rendered Id: 2' ) )
62126212 expect ( spy ) . toHaveBeenCalledTimes ( 1 )
62136213 } )
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+ } )
62146235} )
You can’t perform that action at this time.
0 commit comments