File tree Expand file tree Collapse file tree 4 files changed +32
-10
lines changed Expand file tree Collapse file tree 4 files changed +32
-10
lines changed Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ interface SuccessAction<TData> {
98
98
data : TData | undefined
99
99
type : 'success'
100
100
dataUpdatedAt ?: number
101
- notifySuccess ?: boolean
101
+ manual ?: boolean
102
102
}
103
103
104
104
interface ErrorAction < TError > {
@@ -195,10 +195,7 @@ export class Query<
195
195
}
196
196
}
197
197
198
- setData (
199
- data : TData ,
200
- options ?: SetDataOptions & { notifySuccess : boolean }
201
- ) : TData {
198
+ setData ( data : TData , options ?: SetDataOptions & { manual : boolean } ) : TData {
202
199
const prevData = this . state . data
203
200
204
201
// Use prev data if an isDataEqual function is defined and returns `true`
@@ -214,7 +211,7 @@ export class Query<
214
211
data,
215
212
type : 'success' ,
216
213
dataUpdatedAt : options ?. updatedAt ,
217
- notifySuccess : options ?. notifySuccess ,
214
+ manual : options ?. manual ,
218
215
} )
219
216
220
217
return data
@@ -538,10 +535,12 @@ export class Query<
538
535
dataUpdateCount : state . dataUpdateCount + 1 ,
539
536
dataUpdatedAt : action . dataUpdatedAt ?? Date . now ( ) ,
540
537
error : null ,
541
- fetchFailureCount : 0 ,
542
538
isInvalidated : false ,
543
- fetchStatus : 'idle' ,
544
539
status : 'success' ,
540
+ ...( ! action . manual && {
541
+ fetchStatus : 'idle' ,
542
+ fetchFailureCount : 0 ,
543
+ } ) ,
545
544
}
546
545
case 'error' :
547
546
const error = action . error as unknown
Original file line number Diff line number Diff line change @@ -143,7 +143,7 @@ export class QueryClient {
143
143
const defaultedOptions = this . defaultQueryOptions ( parsedOptions )
144
144
return this . queryCache
145
145
. build ( this , defaultedOptions )
146
- . setData ( data , { ...options , notifySuccess : false } )
146
+ . setData ( data , { ...options , manual : true } )
147
147
}
148
148
149
149
setQueriesData < TData > (
Original file line number Diff line number Diff line change @@ -650,7 +650,7 @@ export class QueryObserver<
650
650
const notifyOptions : NotifyOptions = { }
651
651
652
652
if ( action . type === 'success' ) {
653
- notifyOptions . onSuccess = action . notifySuccess ?? true
653
+ notifyOptions . onSuccess = ! action . manual
654
654
} else if ( action . type === 'error' && ! isCancelledError ( action . error ) ) {
655
655
notifyOptions . onError = true
656
656
}
Original file line number Diff line number Diff line change @@ -356,6 +356,29 @@ describe('queryClient', () => {
356
356
357
357
expect ( queryCache . find ( key ) ! . state . data ) . toBe ( newData )
358
358
} )
359
+
360
+ test ( 'should not set isFetching to false' , async ( ) => {
361
+ const key = queryKey ( )
362
+ queryClient . prefetchQuery ( key , async ( ) => {
363
+ await sleep ( 10 )
364
+ return 23
365
+ } )
366
+ expect ( queryClient . getQueryState ( key ) ) . toMatchObject ( {
367
+ data : undefined ,
368
+ fetchStatus : 'fetching' ,
369
+ } )
370
+ queryClient . setQueryData ( key , 42 )
371
+ expect ( queryClient . getQueryState ( key ) ) . toMatchObject ( {
372
+ data : 42 ,
373
+ fetchStatus : 'fetching' ,
374
+ } )
375
+ await waitFor ( ( ) =>
376
+ expect ( queryClient . getQueryState ( key ) ) . toMatchObject ( {
377
+ data : 23 ,
378
+ fetchStatus : 'idle' ,
379
+ } )
380
+ )
381
+ } )
359
382
} )
360
383
361
384
describe ( 'setQueriesData' , ( ) => {
You can’t perform that action at this time.
0 commit comments