@@ -493,33 +493,39 @@ export function buildSlice({
493493 updateProvidedBy : {
494494 reducer (
495495 draft ,
496- action : PayloadAction < {
497- queryCacheKey : QueryCacheKey
498- providedTags : readonly FullTagDescription < string > [ ]
499- } > ,
496+ action : PayloadAction <
497+ Array < {
498+ queryCacheKey : QueryCacheKey
499+ providedTags : readonly FullTagDescription < string > [ ]
500+ } >
501+ > ,
500502 ) {
501- const { queryCacheKey, providedTags } = action . payload
502-
503- removeCacheKeyFromTags ( draft , queryCacheKey )
503+ for ( const { queryCacheKey, providedTags } of action . payload ) {
504+ removeCacheKeyFromTags ( draft , queryCacheKey )
504505
505- for ( const { type, id } of providedTags ) {
506- const subscribedQueries = ( ( draft . tags [ type ] ??= { } ) [
507- id || '__internal_without_id'
508- ] ??= [ ] )
509- const alreadySubscribed = subscribedQueries . includes ( queryCacheKey )
510- if ( ! alreadySubscribed ) {
511- subscribedQueries . push ( queryCacheKey )
506+ for ( const { type, id } of providedTags ) {
507+ const subscribedQueries = ( ( draft . tags [ type ] ??= { } ) [
508+ id || '__internal_without_id'
509+ ] ??= [ ] )
510+ const alreadySubscribed =
511+ subscribedQueries . includes ( queryCacheKey )
512+ if ( ! alreadySubscribed ) {
513+ subscribedQueries . push ( queryCacheKey )
514+ }
512515 }
513- }
514516
515- // Remove readonly from the providedTags array
516- draft . keys [ queryCacheKey ] =
517- providedTags as FullTagDescription < string > [ ]
517+ // Remove readonly from the providedTags array
518+ draft . keys [ queryCacheKey ] =
519+ providedTags as FullTagDescription < string > [ ]
520+ }
518521 } ,
519- prepare : prepareAutoBatched < {
520- queryCacheKey : QueryCacheKey
521- providedTags : readonly FullTagDescription < string > [ ]
522- } > ( ) ,
522+ prepare :
523+ prepareAutoBatched <
524+ Array < {
525+ queryCacheKey : QueryCacheKey
526+ providedTags : readonly FullTagDescription < string > [ ]
527+ } >
528+ > ( ) ,
523529 } ,
524530 } ,
525531 extraReducers ( builder ) {
@@ -550,21 +556,26 @@ export function buildSlice({
550556 . addMatcher (
551557 isAnyOf ( isFulfilled ( queryThunk ) , isRejectedWithValue ( queryThunk ) ) ,
552558 ( draft , action ) => {
553- writeProvidedTagsForQuery ( draft , action )
559+ writeProvidedTagsForQueries ( draft , [ action ] )
554560 } ,
555561 )
556562 . addMatcher (
557563 querySlice . actions . cacheEntriesUpserted . match ,
558564 ( draft , action ) => {
559- for ( const { queryDescription : arg , value } of action . payload ) {
560- const action : CalculateProvidedByAction = {
561- type : 'UNKNOWN' ,
562- payload : value ,
563- meta : { requestStatus : 'fulfilled' , requestId : 'UNKNOWN' , arg } ,
564- }
565-
566- writeProvidedTagsForQuery ( draft , action )
567- }
565+ const mockActions : CalculateProvidedByAction [ ] = action . payload . map (
566+ ( { queryDescription, value } ) => {
567+ return {
568+ type : 'UNKNOWN' ,
569+ payload : value ,
570+ meta : {
571+ requestStatus : 'fulfilled' ,
572+ requestId : 'UNKNOWN' ,
573+ arg : queryDescription ,
574+ } ,
575+ }
576+ } ,
577+ )
578+ writeProvidedTagsForQueries ( draft , mockActions )
568579 } ,
569580 )
570581 } ,
@@ -592,24 +603,24 @@ export function buildSlice({
592603 delete draft . keys [ queryCacheKey ]
593604 }
594605
595- function writeProvidedTagsForQuery (
606+ function writeProvidedTagsForQueries (
596607 draft : InvalidationState < string > ,
597- action : CalculateProvidedByAction ,
608+ actions : CalculateProvidedByAction [ ] ,
598609 ) {
599- const providedTags = calculateProvidedByThunk (
600- action ,
601- 'providesTags' ,
602- definitions ,
603- assertTagType ,
604- )
605- const { queryCacheKey } = action . meta . arg
610+ const providedByEntries = actions . map ( ( action ) => {
611+ const providedTags = calculateProvidedByThunk (
612+ action ,
613+ 'providesTags' ,
614+ definitions ,
615+ assertTagType ,
616+ )
617+ const { queryCacheKey } = action . meta . arg
618+ return { queryCacheKey, providedTags }
619+ } )
606620
607621 invalidationSlice . caseReducers . updateProvidedBy (
608622 draft ,
609- invalidationSlice . actions . updateProvidedBy ( {
610- queryCacheKey,
611- providedTags,
612- } ) ,
623+ invalidationSlice . actions . updateProvidedBy ( providedByEntries ) ,
613624 )
614625 }
615626
0 commit comments