@@ -53,6 +53,7 @@ import type {
5353 StartQueryActionCreatorOptions ,
5454} from './buildInitiate'
5555import { forceQueryFnSymbol , isUpsertQuery } from './buildInitiate'
56+ import type { AllSelectors } from './buildSelectors'
5657import type { ApiEndpointQuery , PrefetchOptions } from './module'
5758import {
5859 createAsyncThunk ,
@@ -307,13 +308,15 @@ export function buildThunks<
307308 serializeQueryArgs,
308309 api,
309310 assertTagType,
311+ selectors,
310312} : {
311313 baseQuery : BaseQuery
312314 reducerPath : ReducerPath
313315 context : ApiContext < Definitions >
314316 serializeQueryArgs : InternalSerializeQueryArgs
315317 api : Api < BaseQuery , Definitions , ReducerPath , any >
316318 assertTagType : AssertTagTypes
319+ selectors : AllSelectors
317320} ) {
318321 type State = RootState < any , string , ReducerPath >
319322
@@ -609,8 +612,10 @@ export function buildThunks<
609612 // Start by looking up the existing InfiniteData value from state,
610613 // falling back to an empty value if it doesn't exist yet
611614 const blankData = { pages : [ ] , pageParams : [ ] }
612- const cachedData = getState ( ) [ reducerPath ] . queries [ arg . queryCacheKey ]
613- ?. data as InfiniteData < unknown , unknown > | undefined
615+ const cachedData = selectors . selectQueryEntry (
616+ getState ( ) ,
617+ arg . queryCacheKey ,
618+ ) ?. data as InfiniteData < unknown , unknown > | undefined
614619 // Don't want to use `isForcedQuery` here, because that
615620 // includes `refetchOnMountOrArgChange`.
616621 const existingData = (
@@ -720,9 +725,9 @@ In the case of an unhandled error, no tags will be "provided" or "invalidated".`
720725 arg : QueryThunkArg ,
721726 state : RootState < any , string , ReducerPath > ,
722727 ) {
723- const requestState = state [ reducerPath ] ?. queries ?. [ arg . queryCacheKey ]
728+ const requestState = selectors . selectQueryEntry ( state , arg . queryCacheKey )
724729 const baseFetchOnMountOrArgChange =
725- state [ reducerPath ] ?. config . refetchOnMountOrArgChange
730+ selectors . selectConfig ( state ) . refetchOnMountOrArgChange
726731
727732 const fulfilledVal = requestState ?. fulfilledTimeStamp
728733 const refetchVal =
0 commit comments