Skip to content

Commit

Permalink
fix upserting
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Sep 2, 2022
1 parent d9e481b commit e71d9ba
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/toolkit/src/query/core/buildSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ export function buildSlice({
extraReducers(builder) {
builder
.addCase(queryThunk.pending, (draft, { meta, meta: { arg } }) => {
if (arg.subscribe) {
const upserting = isUpsertQuery(arg)
if (arg.subscribe || upserting) {
// only initialize substate if we want to subscribe to it
draft[arg.queryCacheKey] ??= {
status: QueryStatus.uninitialized,
Expand All @@ -148,7 +149,7 @@ export function buildSlice({
substate.status = QueryStatus.pending

substate.requestId =
isUpsertQuery(arg) && substate.requestId
upserting && substate.requestId
? // for `upsertQuery` **updates**, keep the current `requestId`
substate.requestId
: // for normal queries or `upsertQuery` **inserts** always update the `requestId`
Expand Down

0 comments on commit e71d9ba

Please sign in to comment.