diff --git a/packages/toolkit/src/query/core/buildMiddleware/index.ts b/packages/toolkit/src/query/core/buildMiddleware/index.ts index 840d7a03bb..09f2412e12 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/index.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/index.ts @@ -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) } diff --git a/packages/toolkit/src/query/core/buildThunks.ts b/packages/toolkit/src/query/core/buildThunks.ts index e912922d1f..6da388bb85 100644 --- a/packages/toolkit/src/query/core/buildThunks.ts +++ b/packages/toolkit/src/query/core/buildThunks.ts @@ -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.