@@ -14,7 +14,6 @@ import {
1414 RefetchOptions ,
1515 SetDataOptions ,
1616} from '@tanstack/query-core' ;
17- import { LinkedAbortController } from 'linked-abort-controller' ;
1817import {
1918 action ,
2019 reaction ,
@@ -40,6 +39,7 @@ import { Query } from './query';
4039import { QueryClient } from './query-client' ;
4140import { AnyQueryClient , QueryClientHooks } from './query-client.types' ;
4241import { QueryFeatures } from './query.types' ;
42+ import { Destroyable } from './utils/destroyable' ;
4343
4444const originalQueryProperties = [
4545 'data' ,
@@ -80,14 +80,14 @@ export class InfiniteQuery<
8080 TData = InfiniteData < TQueryFnData , TPageParam > ,
8181 TQueryKey extends QueryKey = QueryKey ,
8282 >
83+ extends Destroyable
8384 implements
8485 Disposable ,
8586 Pick <
8687 InfiniteQueryObserverBaseResult < TData , TError > ,
8788 ( typeof originalQueryProperties ) [ number ]
8889 >
8990{
90- protected abortController : LinkedAbortController ;
9191 protected queryClient : AnyQueryClient ;
9292
9393 protected _result : InfiniteQueryObserverResult < TData , TError > ;
@@ -313,6 +313,9 @@ export class InfiniteQuery<
313313 config = args [ 0 ] ;
314314 getDynamicOptions = args [ 0 ] . options ;
315315 }
316+
317+ super ( config . abortSignal ) ;
318+
316319 this . cumulativeQueryKeyHashesSet = new Set ( ) ;
317320
318321 const { queryKey : queryKeyOrDynamicQueryKey , ...restOptions } = config ;
@@ -322,7 +325,6 @@ export class InfiniteQuery<
322325 queryClient,
323326 } ;
324327
325- this . abortController = new LinkedAbortController ( config . abortSignal ) ;
326328 this . queryClient = queryClient ;
327329 this . _result = undefined as any ;
328330 this . isResultRequsted = false ;
@@ -360,7 +362,6 @@ export class InfiniteQuery<
360362
361363 observable . deep ( this , '_result' ) ;
362364 observable . ref ( this , 'isResultRequsted' ) ;
363- action ( this , 'handleAbort' ) ;
364365 action . bound ( this , 'setData' ) ;
365366 action . bound ( this , 'update' ) ;
366367 action . bound ( this , 'updateResult' ) ;
@@ -491,7 +492,7 @@ export class InfiniteQuery<
491492 this . updateResult ,
492493 ) ;
493494 this . abortController . signal . addEventListener ( 'abort' , ( ) =>
494- this . handleAbort ( ) ,
495+ this . handleDestroy ( ) ,
495496 ) ;
496497 }
497498
@@ -625,51 +626,11 @@ export class InfiniteQuery<
625626 return await Query . prototype . start . call ( this , params ) ;
626627 }
627628
628- protected handleAbort ( ) {
629- this . _observerSubscription ?.( ) ;
630-
631- this . doneListeners = [ ] ;
632- this . errorListeners = [ ] ;
633-
634- this . queryObserver . destroy ( ) ;
635- this . isResultRequsted = false ;
636-
637- if ( this . features . resetOnDestroy ) {
638- this . reset ( ) ;
639- }
640-
641- if ( this . features . removeOnDestroy ) {
642- this . remove ( {
643- safe : this . features . removeOnDestroy === 'safe' ,
644- } ) ;
645- }
646-
647- delete this . _observerSubscription ;
648-
649- this . cumulativeQueryKeyHashesSet . clear ( ) ;
650-
629+ protected handleDestroy ( ) {
630+ // @ts -expect-error
631+ Query . prototype . cleanup . call ( this ) ;
651632 this . hooks ?. onInfiniteQueryDestroy ?.( this ) ;
652633 }
653-
654- destroy ( ) {
655- this . abortController . abort ( ) ;
656- }
657-
658- /**
659- * @deprecated use `destroy`. This method will be removed in next major release
660- */
661- dispose ( ) {
662- this . destroy ( ) ;
663- }
664-
665- [ Symbol . dispose ] ( ) : void {
666- this . destroy ( ) ;
667- }
668-
669- // Firefox fix (Symbol.dispose is undefined in FF)
670- [ Symbol . for ( 'Symbol.dispose' ) ] ( ) : void {
671- this . destroy ( ) ;
672- }
673634}
674635
675636/**
0 commit comments