Thank you for improving the asynchronous state management for TS/JS ecosystem with a greatest library.
I think it's good if the user becomes a more predictable queryKey.
I will write the relevant PR.
Describe the bug#
Problem Statement#
When using query keys containing circular references or complex objects (e.g., React elements in DEV), JSON.stringify in query key serialization triggers maximum call stack errors due to:
- Recursive object comparison in replacer functions
- Circular dependencies in nested objects
This results in unpredictable behavior and debugging difficulties for developers using non-serializable query keys.
When,
const div = <div>asfd</div>;
const {data} = useQuery({
queryKey: [div],
queryFn:
});
const obj = {name: "root"};
obj.self = obj;
const {data} = useQuery({
queryKey: [obj],
queryFn:
});
Then,
Your minimal, reproducible example#
https://codesandbox.io/p/sandbox/3rz288?file=%2Fsrc%2FApp.tsx
Steps to reproduce#
- use
useQuery
- add circular object to
queryKey
- fetch
- error
Expected behavior#
As a user, I wanted a more accurate error (Circular), or for the circular to be ignored.
However, a Maximum call stack error occurred, and a lot of time was spent on debugging.
How often does this bug happen?#
Every time
Screenshots or Videos#
No response
Platform#
OS: macOS
browser: Chrome
Tanstack Query adapter#
react-query
TanStack Query version#
5.66.0
TypeScript version#
5.6.2
https://github.com/TanStack/query/pull/8626#issuecomment-2653811845