Describe the bug#
The meta and mutationKey on previous mutations get updated when state in a component is updated.
This only happens the first time the state updates and only on the last mutation in the cache.
Your minimal, reproducible example#
https://stackblitz.com/edit/vitejs-vite-pchfwb?file=src%2FApp.tsx
Steps to reproduce#
- Click the button "Run mutation"
- See the website list the mutation: "0 = 0 = 0 is true" ([value] = [key] = [meta] is [equal])
- Click the button "Bump state"
- See the website list the mutation: "0 = 1 = 1 is false"
Expected behavior#
I expect that all existing mutations should not be altered when some state updates.
Meaning step 4. should stay "0 = 0 = 0 is true".
Meaning that the mutation key and meta object should still hold the value 0 that was the value when the mutation happened.
How often does this bug happen?#
Every time
Screenshots or Videos#
No response
Platform#
- OS: Windows
- Browser: Edge
- Version: 119.0.2151.58
Tanstack Query adapter#
react-query
TanStack Query version#
5.18.1
TypeScript version#
No response
Additional context#
You can also see the values being updated in the ReactQueryDevtools.
I see it is fixed when the key is updated. But I would also assume
metashould not be updated on old mutations. This is actually happening when a key is missing or the same.Your minimal, reproducible example#
https://stackblitz.com/edit/vitejs-vite-jpzeoh?file=src%2FApp.tsx
Steps to reproduce#
Expected behavior#
I expect that all existing mutations should not be altered when some state updates. Meaning step 5. should stay "0 = 0 is true". Meaning that the meta object should still hold the value 0 that was the value when the mutation happened.
Does my reasoning and what I expect sound like what should happen, @TkDodo? Also not that meta is only updated every second time, bug is not triggered on odd number of "Bump state" clicks.