Skip to content

Commit e7e9591

Browse files
authored
Merge pull request #2644 from reduxjs/bugfix/rtkq-middleware-fixes
2 parents ce98d69 + d2e200a commit e7e9591

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

packages/toolkit/src/query/core/buildMiddleware/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,12 @@ export function buildMiddleware<
9191
// This looks for actions that aren't specific to the API slice
9292
windowEventsHandler(action, mwApi, stateBefore)
9393

94-
if (isThisApiSliceAction(action)) {
95-
// Only run these additional checks if the actions are part of the API slice
94+
if (
95+
isThisApiSliceAction(action) ||
96+
context.hasRehydrationInfo(action)
97+
) {
98+
// Only run these additional checks if the actions are part of the API slice,
99+
// or the action has hydration-related data
96100
for (let handler of handlers) {
97101
handler(action, mwApi, stateBefore)
98102
}

packages/toolkit/src/query/core/buildThunks.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,16 +480,18 @@ In the case of an unhandled error, no tags will be "provided" or "invalidated".`
480480
const fulfilledVal = requestState?.fulfilledTimeStamp
481481

482482
// Order of these checks matters.
483-
// In order for `upsertQueryData` to successfully run while an existing request is
484-
/// in flight, we have to check `isForcedQuery` before `status === 'pending'`,
485-
// otherwise `queryThunk` will bail out and not run at all.
486-
487-
// if this is forced, continue
488-
if (isForcedQuery(arg, state)) return true
483+
// In order for `upsertQueryData` to successfully run while an existing request is in flight,
484+
/// we have to check for that first, otherwise `queryThunk` will bail out and not run at all.
485+
const isUpsertQuery =
486+
typeof arg[forceQueryFnSymbol] === 'function' && arg.forceRefetch
487+
if (isUpsertQuery) return true
489488

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

492+
// if this is forced, continue
493+
if (isForcedQuery(arg, state)) return true
494+
493495
// Pull from the cache unless we explicitly force refetch or qualify based on time
494496
if (fulfilledVal)
495497
// Value is cached and we didn't specify to refresh, skip it.

0 commit comments

Comments
 (0)