Skip to content

Commit

Permalink
refetch with initiate so that runningQueries are tracked properly
Browse files Browse the repository at this point in the history
  • Loading branch information
EskiMojo14 committed May 4, 2024
1 parent 171f9e0 commit 6c2da09
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
22 changes: 9 additions & 13 deletions packages/toolkit/src/query/core/buildMiddleware/index.ts
Expand Up @@ -11,12 +11,12 @@ import type {
FullTagDescription,
} from '../../endpointDefinitions'
import type { QueryStatus, QuerySubState, RootState } from '../apiState'
import type { QueryThunkArg } from '../buildThunks'
import { buildCacheCollectionHandler } from './cacheCollection'
import { buildInvalidationByTagsHandler } from './invalidationByTags'
import { buildPollingHandler } from './polling'
import type {
BuildMiddlewareInput,
BuildSubMiddlewareInput,
InternalHandlerBuilder,
InternalMiddlewareState,
} from './types'
Expand Down Expand Up @@ -63,7 +63,7 @@ export function buildMiddleware<
currentSubscriptions: {},
}

const builderArgs = {
const builderArgs: BuildSubMiddlewareInput = {
...(input as any as BuildMiddlewareInput<
EndpointDefinitions,
string,
Expand Down Expand Up @@ -135,17 +135,13 @@ export function buildMiddleware<
QuerySubState<any>,
{ status: QueryStatus.uninitialized }
>,
queryCacheKey: string,
override: Partial<QueryThunkArg> = {},
) {
return queryThunk({
type: 'query',
endpointName: querySubState.endpointName,
originalArgs: querySubState.originalArgs,
subscribe: false,
forceRefetch: true,
queryCacheKey: queryCacheKey as any,
...override,
})
return api.endpoints[querySubState.endpointName].initiate(
querySubState.originalArgs as never,
{
forceRefetch: true,
subscribe: false,
},
)
}
}
Expand Up @@ -122,7 +122,7 @@ export const buildInvalidationByTagsHandler: InternalHandlerBuilder = ({
}),
)
} else if (querySubState.status !== QueryStatus.uninitialized) {
mwApi.dispatch(refetchQuery(querySubState, queryCacheKey))
mwApi.dispatch(refetchQuery(querySubState))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/core/buildMiddleware/polling.ts
Expand Up @@ -78,7 +78,7 @@ export const buildPollingHandler: InternalHandlerBuilder = ({
pollingInterval: lowestPollingInterval,
timeout: setTimeout(() => {
if (state.config.focused || !skipPollingIfUnfocused) {
api.dispatch(refetchQuery(querySubState, queryCacheKey))
api.dispatch(refetchQuery(querySubState))
}
startNextPoll({ queryCacheKey }, api)
}, lowestPollingInterval),
Expand Down
6 changes: 2 additions & 4 deletions packages/toolkit/src/query/core/buildMiddleware/types.ts
@@ -1,8 +1,8 @@
import type {
Action,
AsyncThunkAction,
Middleware,
MiddlewareAPI,
ThunkAction,
ThunkDispatch,
UnknownAction,
} from '@reduxjs/toolkit'
Expand Down Expand Up @@ -64,9 +64,7 @@ export interface BuildSubMiddlewareInput
QuerySubState<any>,
{ status: QueryStatus.uninitialized }
>,
queryCacheKey: string,
override?: Partial<QueryThunkArg>,
): AsyncThunkAction<ThunkResult, QueryThunkArg, {}>
): ThunkAction<unknown, unknown, unknown, UnknownAction>
isThisApiSliceAction: (action: Action) => boolean
}

Expand Down
Expand Up @@ -58,7 +58,7 @@ export const buildWindowEventHandler: InternalHandlerBuilder = ({
}),
)
} else if (querySubState.status !== QueryStatus.uninitialized) {
api.dispatch(refetchQuery(querySubState, queryCacheKey))
api.dispatch(refetchQuery(querySubState))
}
}
}
Expand Down

0 comments on commit 6c2da09

Please sign in to comment.