Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix assorted issues with the RTKQ middleware refactor #2644

Merged
merged 2 commits into from
Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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