Skip to content

Commit

Permalink
Merge pull request #2779 from reduxjs/pr/batched-skiptoken-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson authored Oct 18, 2022
2 parents daf8d9a + 6f1f0a4 commit b92fb8d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
13 changes: 9 additions & 4 deletions packages/toolkit/src/query/core/buildSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,19 @@ export function buildSlice({
draft[queryCacheKey]![requestId] = options
}
return true
} else if (unsubscribeQueryResult.match(action)) {
}
if (unsubscribeQueryResult.match(action)) {
const { queryCacheKey, requestId } = action.payload
if (draft[queryCacheKey]) {
delete draft[queryCacheKey]![requestId]
}
return true
} else if (querySlice.actions.removeQueryResult.match(action)) {
}
if (querySlice.actions.removeQueryResult.match(action)) {
delete draft[action.payload.queryCacheKey]
} else if (queryThunk.pending.match(action)) {
return true
}
if (queryThunk.pending.match(action)) {
const {
meta: { arg, requestId },
} = action
Expand All @@ -447,7 +451,8 @@ export function buildSlice({

return true
}
} else if (queryThunk.rejected.match(action)) {
}
if (queryThunk.rejected.match(action)) {
const {
meta: { condition, arg, requestId },
} = action
Expand Down
4 changes: 3 additions & 1 deletion packages/toolkit/src/query/react/buildHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,9 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
)
lastResult = undefined
}

if (queryArgs === skipToken) {
lastResult = undefined
}
// data is the last known good request result we have tracked - or if none has been tracked yet the last good result for the current args
let data = currentState.isSuccess ? currentState.data : lastResult?.data
if (data === undefined) data = currentState.data
Expand Down
12 changes: 2 additions & 10 deletions packages/toolkit/src/query/tests/buildHooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2379,11 +2379,7 @@ describe('skip behaviour', () => {
await act(async () => {
rerender([1, { skip: true }])
})
expect(result.current).toEqual({
...uninitialized,
currentData: undefined,
data: { name: 'Timmy' },
})
expect(result.current).toEqual(uninitialized)
await delay(1)
expect(subscriptionCount('getUser(1)')).toBe(0)
})
Expand Down Expand Up @@ -2415,11 +2411,7 @@ describe('skip behaviour', () => {
await act(async () => {
rerender([skipToken])
})
expect(result.current).toEqual({
...uninitialized,
currentData: undefined,
data: { name: 'Timmy' },
})
expect(result.current).toEqual(uninitialized)
await delay(1)
expect(subscriptionCount('getUser(1)')).toBe(0)
})
Expand Down

0 comments on commit b92fb8d

Please sign in to comment.