Skip to content

Commit

Permalink
Merge pull request #2644 from reduxjs/bugfix/rtkq-middleware-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson authored Aug 28, 2022
2 parents ce98d69 + d2e200a commit e7e9591
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 6 additions & 2 deletions packages/toolkit/src/query/core/buildMiddleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ export function buildMiddleware<
// This looks for actions that aren't specific to the API slice
windowEventsHandler(action, mwApi, stateBefore)

if (isThisApiSliceAction(action)) {
// Only run these additional checks if the actions are part of the API slice
if (
isThisApiSliceAction(action) ||
context.hasRehydrationInfo(action)
) {
// Only run these additional checks if the actions are part of the API slice,
// or the action has hydration-related data
for (let handler of handlers) {
handler(action, mwApi, stateBefore)
}
Expand Down
14 changes: 8 additions & 6 deletions packages/toolkit/src/query/core/buildThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,18 @@ In the case of an unhandled error, no tags will be "provided" or "invalidated".`
const fulfilledVal = requestState?.fulfilledTimeStamp

// Order of these checks matters.
// In order for `upsertQueryData` to successfully run while an existing request is
/// in flight, we have to check `isForcedQuery` before `status === 'pending'`,
// otherwise `queryThunk` will bail out and not run at all.

// if this is forced, continue
if (isForcedQuery(arg, state)) return true
// In order for `upsertQueryData` to successfully run while an existing request is in flight,
/// we have to check for that first, otherwise `queryThunk` will bail out and not run at all.
const isUpsertQuery =
typeof arg[forceQueryFnSymbol] === 'function' && arg.forceRefetch
if (isUpsertQuery) return true

// Don't retry a request that's currently in-flight
if (requestState?.status === 'pending') return false

// if this is forced, continue
if (isForcedQuery(arg, state)) return true

// Pull from the cache unless we explicitly force refetch or qualify based on time
if (fulfilledVal)
// Value is cached and we didn't specify to refresh, skip it.
Expand Down

0 comments on commit e7e9591

Please sign in to comment.