@@ -113,6 +113,9 @@ export class Query<
113113 protected errorListeners : QueryErrorListener < TError > [ ] ;
114114 protected doneListeners : QueryDoneListener < TData > [ ] ;
115115
116+ protected cumulativeQueryHash : boolean ;
117+ protected cumulativeQueryKeyHashesSet : Set < string > ;
118+
116119 protected config : QueryConfig <
117120 TQueryFnData ,
118121 TError ,
@@ -266,6 +269,7 @@ export class Query<
266269 config = args [ 0 ] ;
267270 getDynamicOptions = args [ 0 ] . options ;
268271 }
272+ this . cumulativeQueryKeyHashesSet = new Set ( ) ;
269273
270274 const { queryKey : queryKeyOrDynamicQueryKey , ...restOptions } = config ;
271275
@@ -284,6 +288,8 @@ export class Query<
284288 this . hooks =
285289 'hooks' in this . queryClient ? this . queryClient . hooks : undefined ;
286290 this . isLazy = this . config . lazy ;
291+ this . cumulativeQueryHash = ! ! config . cumulativeQueryHash ;
292+
287293 let transformError : QueryFeatures [ 'transformError' ] = config . transformError ;
288294
289295 if ( 'queryFeatures' in queryClient ) {
@@ -294,6 +300,10 @@ export class Query<
294300 this . isEnabledOnResultDemand =
295301 queryClient . queryFeatures . enableOnDemand ?? false ;
296302 }
303+ if ( config . cumulativeQueryHash === undefined ) {
304+ this . cumulativeQueryHash =
305+ queryClient . queryFeatures . cumulativeQueryHash ?? false ;
306+ }
297307 if ( ! transformError ) {
298308 transformError = queryClient . queryFeatures . transformError ;
299309 }
@@ -530,6 +540,10 @@ export class Query<
530540 ) {
531541 options . queryHash = this . createQueryHash ( options . queryKey , options ) ;
532542
543+ if ( this . cumulativeQueryHash ) {
544+ this . cumulativeQueryKeyHashesSet . add ( options . queryHash ) ;
545+ }
546+
533547 // If the on-demand query mode is enabled (when using the result property)
534548 // then, if the user does not request the result, the queries should not be executed
535549 // to do this, we hold the original value of the enabled option
@@ -579,6 +593,14 @@ export class Query<
579593 }
580594
581595 async reset ( params ?: QueryResetParams , options ?: ResetOptions ) {
596+ if ( this . cumulativeQueryHash ) {
597+ return await this . queryClient . resetQueries ( {
598+ predicate : ( query ) =>
599+ this . cumulativeQueryKeyHashesSet . has ( query . options . queryHash ! ) ,
600+ ...params ,
601+ } ) ;
602+ }
603+
582604 return await this . queryClient . resetQueries (
583605 {
584606 queryKey : this . options . queryKey ,
@@ -590,6 +612,14 @@ export class Query<
590612 }
591613
592614 remove ( params ?: QueryRemoveParams ) {
615+ if ( this . cumulativeQueryHash ) {
616+ return this . queryClient . removeQueries ( {
617+ predicate : ( query ) =>
618+ this . cumulativeQueryKeyHashesSet . has ( query . options . queryHash ! ) ,
619+ ...params ,
620+ } ) ;
621+ }
622+
593623 return this . queryClient . removeQueries ( {
594624 queryKey : this . options . queryKey ,
595625 exact : true ,
@@ -657,6 +687,8 @@ export class Query<
657687
658688 delete this . _observerSubscription ;
659689
690+ this . cumulativeQueryKeyHashesSet . clear ( ) ;
691+
660692 this . hooks ?. onQueryDestroy ?.( this ) ;
661693 }
662694
0 commit comments