File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -227,7 +227,7 @@ export class Query<
227227
228228 destroy ( ) : void {
229229 this . clearGcTimeout ( )
230- this . cancel ( )
230+ this . cancel ( { silent : true } )
231231 }
232232
233233 reset ( ) : void {
Original file line number Diff line number Diff line change @@ -282,6 +282,36 @@ describe('query', () => {
282282 expect ( isCancelledError ( error ) ) . toBe ( true )
283283 } )
284284
285+ test ( 'should not error if reset while loading' , async ( ) => {
286+ const key = queryKey ( )
287+
288+ const queryFn = jest . fn ( )
289+
290+ queryFn . mockImplementation ( async ( ) => {
291+ await sleep ( 10 )
292+ throw new Error ( )
293+ } )
294+
295+ queryClient . fetchQuery ( key , queryFn , {
296+ retry : 3 ,
297+ retryDelay : 10 ,
298+ } )
299+
300+ // Ensure the query is loading
301+ const query = queryCache . find ( key ) !
302+ expect ( query . state . status ) . toBe ( 'loading' )
303+
304+ // Reset the query while it is loading
305+ query . reset ( )
306+
307+ await sleep ( 100 )
308+
309+ // The query should
310+ expect ( queryFn ) . toHaveBeenCalledTimes ( 1 ) // have been called,
311+ expect ( query . state . error ) . toBe ( null ) // not have an error, and
312+ expect ( query . state . status ) . toBe ( 'idle' ) // not be loading any longer
313+ } )
314+
285315 test ( 'should be able to refetch a cancelled query' , async ( ) => {
286316 const key = queryKey ( )
287317
You can’t perform that action at this time.
0 commit comments