Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event handlers have stale state #5056

Closed
srph opened this issue Mar 1, 2023 · 0 comments · Fixed by #5085
Closed

Event handlers have stale state #5056

srph opened this issue Mar 1, 2023 · 0 comments · Fixed by #5085
Labels
bug Something isn't working package: query-core

Comments

@srph
Copy link

srph commented Mar 1, 2023

Describe the bug

When the onSuccess handler for useMutation fires, you will have stale values of the state used inside onSuccess.

My thinking is that useMutation probably uses the value of onSuccess when mutate() is ran.

Your minimal, reproducible example

https://codesandbox.io/s/focused-buck-fxbe50?file=/src/App.tsx:966-1008

Steps to reproduce

  • Open Devtools
  • Press "Mutate" button
  • While the mutation is on-going, press the "Close" button

Expected behavior

As a user, I expected isOpen to be false. Instead, I got true -- which was the value of isOpen when the mutation ran.

How often does this bug happen?

Every time

Screenshots or Videos

image

Platform

  • OS: macOS Monterey
  • Browser: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36'

TanStack Query version

v3.39.3

TypeScript version

No response

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working package: query-core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants