-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Describe the bug
The isPending
state of a mutation does not reset to false
but remains true
if an error is thrown in the onError
function of the mutate
function, and the error did originate either within the mutationFn
or in the onSuccess
passed to the useMutate
function.
Furthermore, the queryClient must be configured to invalidate all queries when a mutation settles, and a query must be present in the tree.
In this exact scenario, I could reproduce this bug. When deviating from this setting, the isPending
state of the mutation did reset to false
as one would expect.
Your minimal, reproducible example
https://stackblitz.com/edit/tanstack-query-bwruozre?file=src%2Findex.tsx&preset=node
Steps to reproduce
- Open the provided link (https://stackblitz.com/edit/tanstack-query-bwruozre?file=src%2Findex.tsx&preset=node)
- Click on the button "Action!"
Expected behavior
The value of isPending
of my mutation should be false
again - as it does if you remove line 69, which throws the error inside the onError function of the mutate
call.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Chrome v140.0.7339.133
Tanstack Query adapter
react-query
TanStack Query version
5.89.0
TypeScript version
5.9.2
Additional context
I found this error while trying to check what would happen if an onSuccess
or onError
callback would throw an error.