Skip to content

Commit 8e24ebd

Browse files
authored
fix: accept null values in mutate function (TanStack#1740)
1 parent 2164530 commit 8e24ebd

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/core/mutationObserver.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ export class MutationObserver<
116116

117117
this.currentMutation = this.client.getMutationCache().build(this.client, {
118118
...this.options,
119-
variables: variables ?? this.options.variables,
119+
variables:
120+
typeof variables !== 'undefined' ? variables : this.options.variables,
120121
})
121122

122123
this.currentMutation.addObserver(this)

src/core/tests/mutations.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ describe('mutations', () => {
2424
expect(result).toBe(result)
2525
})
2626

27+
test('mutate should accept null values', async () => {
28+
let variables
29+
30+
const mutation = new MutationObserver(queryClient, {
31+
mutationFn: async (vars: unknown) => {
32+
variables = vars
33+
return vars
34+
},
35+
})
36+
37+
mutation.mutate(null)
38+
39+
await sleep(10)
40+
41+
expect(variables).toBe(null)
42+
})
43+
2744
test('setMutationDefaults should be able to set defaults', async () => {
2845
const key = queryKey()
2946

0 commit comments

Comments
 (0)