You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the mutation hook in combination with NextJS Server Action and the user makes multiple POST requests (e.g. likes/deletions), if the ongoing requests haven't finished by the time the user decides to navigate to another page, the useIsMutating hook will stop tracking them and it will get stuck with the number of unfinished requests from the previous page.
This problem does not occur when using a Route Handler. It only occurs in a combination with Server Actions!
Describe the bug
When using the mutation hook in combination with NextJS Server Action and the user makes multiple POST requests (e.g. likes/deletions), if the ongoing requests haven't finished by the time the user decides to navigate to another page, the useIsMutating hook will stop tracking them and it will get stuck with the number of unfinished requests from the previous page.
This problem does not occur when using a Route Handler. It only occurs in a combination with Server Actions!
Your minimal, reproducible example
https://codesandbox.io/p/github/flnx/next-actions-and-tanstack-mutations/main
Steps to reproduce
The problem will occur when using this hook (with server actions)
A work-around is to use the hook that makes requests to a route handler:
Expected behavior
I expected the useIsMutating hook to update correctly when navigating to another page when using server actions, just like using route handlers
How often does this bug happen?
Every time
Screenshots or Videos
Using mutation with NextJS Server Action
With.Server.Action_preview.mp4
Using mutation with NextJS Route Handler
With.Route.Handler_preview.mp4
Platform
Windows 11, Firefox 126.0 (64-bit)
Tanstack Query adapter
react-query
TanStack Query version
5.20.5
TypeScript version
5
Additional context
No response
The text was updated successfully, but these errors were encountered: