`setQueriesData` with `BigInt` in `queryKey` Error #9567
Send to my agentDescribe the bug#
When setQueriesData is called with filters (e.g., { queryKey: ['todos'], exact: false }), it attempts to match and update existing queries. However, it appears that setQueriesData does not utilize the queryKeyHashFn provided to the original useQuery hook during this matching and update process.
If a queryKey contains a data type that requires custom serialization, like BigInt, this results in a serialization error because the default JSON.stringify is used internally by setQueriesData, which does not know how to handle BigInt.
In this example, we have a query with queryKey: ['todos', BigInt(1)] and a queryKeyHashFn to handle the BigInt. When a mutation succeeds, we call setQueriesData to update all queries that start with ['todos']. This triggers the error.
Your minimal, reproducible example#
https://stackblitz.com/edit/vitejs-vite-g2sbqzq8?file=README.md
Steps to reproduce#
- Run the development server with
npm run dev. - Open the application in your browser.
- Open the developer console.
- Click on one of the todo items.
Expected behavior#
- Expected: The query data is updated, and the UI reflects the change without any errors in the console.
- Actual: An error is thrown and caught in the
onSuccesshandler of the mutation:TypeError: Do not know how to serialize a BigInt. The UI is not updated via the query cache.
How often does this bug happen?#
Every time
Screenshots or Videos#
https://github.com/user-attachments/assets/b70a0aba-f9a3-4eb4-bf4d-aa07a73059a3
Platform#
- OS: macOS
- Chrome
- Version 139.0.7258.67
Tanstack Query adapter#
vue-query
TanStack Query version#
5.85.3
TypeScript version#
No response
Additional context#
No response
TkDodo closed this
TkDodo added labelsduplicate
Thank you!
Sign in to join this conversation.
we had this before, and I concluded back then that this isn’t worth fixing
On the contrary, I would rather go as far as to deprecate
queryKeyHashFnonuseQueryitself and only allow it globally as a default as described in the linked comment. Otherwise, it means users would have to drill it along everywhere because without the correct hash, we can’t find the query and its options which contains the hashFn ...