File tree Expand file tree Collapse file tree 3 files changed +31
-14
lines changed Expand file tree Collapse file tree 3 files changed +31
-14
lines changed Original file line number Diff line number Diff line change 1- import { DefaultedQueryObserverOptions , RefetchPageFilters } from './types'
1+ import { RefetchPageFilters } from './types'
22import {
33 isServer ,
44 isValidTimeout ,
@@ -224,14 +224,7 @@ export class QueryObserver<
224224 }
225225
226226 trackResult (
227- result : QueryObserverResult < TData , TError > ,
228- defaultedOptions : DefaultedQueryObserverOptions <
229- TQueryFnData ,
230- TError ,
231- TData ,
232- TQueryData ,
233- TQueryKey
234- >
227+ result : QueryObserverResult < TData , TError >
235228 ) : QueryObserverResult < TData , TError > {
236229 const trackedResult = { } as QueryObserverResult < TData , TError >
237230
@@ -246,10 +239,6 @@ export class QueryObserver<
246239 } )
247240 } )
248241
249- if ( defaultedOptions . useErrorBoundary ) {
250- this . trackedProps . add ( 'error' )
251- }
252-
253242 return trackedResult
254243 }
255244
@@ -606,6 +595,10 @@ export class QueryObserver<
606595
607596 const includedProps = new Set ( notifyOnChangeProps ?? this . trackedProps )
608597
598+ if ( this . options . useErrorBoundary ) {
599+ includedProps . add ( 'error' )
600+ }
601+
609602 return Object . keys ( result ) . some ( key => {
610603 const typedKey = key as keyof QueryObserverResult
611604 const changed = result [ typedKey ] !== prevResult [ typedKey ]
Original file line number Diff line number Diff line change @@ -2672,6 +2672,30 @@ describe('useQuery', () => {
26722672 consoleMock . mockRestore ( )
26732673 } )
26742674
2675+ it ( 'should update with data if we observe no properties and useErrorBoundary' , async ( ) => {
2676+ const key = queryKey ( )
2677+
2678+ let result : UseQueryResult < string > | undefined
2679+
2680+ function Page ( ) {
2681+ const query = useQuery ( key , ( ) => Promise . resolve ( 'data' ) , {
2682+ useErrorBoundary : true ,
2683+ } )
2684+
2685+ React . useEffect ( ( ) => {
2686+ result = query
2687+ } )
2688+
2689+ return null
2690+ }
2691+
2692+ renderWithClient ( queryClient , < Page /> )
2693+
2694+ await sleep ( 10 )
2695+
2696+ expect ( result ?. data ) . toBe ( 'data' )
2697+ } )
2698+
26752699 it ( 'should set status to error instead of throwing when error should not be thrown' , async ( ) => {
26762700 const key = queryKey ( )
26772701 const consoleMock = mockConsoleError ( )
Original file line number Diff line number Diff line change @@ -134,7 +134,7 @@ export function useBaseQuery<
134134
135135 // Handle result property usage tracking
136136 if ( ! defaultedOptions . notifyOnChangeProps ) {
137- result = observer . trackResult ( result , defaultedOptions )
137+ result = observer . trackResult ( result )
138138 }
139139
140140 return result
You can’t perform that action at this time.
0 commit comments