Describe the bug
When a disabled query is registered with undefined in its queryKey, invalidation stops working for other queries that have null in the same key position.
This behavior is unexpected, since null and undefined should not be treated as equivalent or conflicting in this context.
Your minimal, reproducible example
https://codesandbox.io/p/sandbox/s3fw8s
Steps to reproduce
- Define a disabled query with
undefined in the key:
useQuery({
queryKey: ['query', undefined],
enabled: false,
});
- Define an enabled query with
null in the key:
useQuery({
queryKey: ['query', null],
queryFn: () => Math.random()
});
- Invalidate the second query:
useQueryClient().invalidateQueries({ queryKey: ['query', null] })
Expected behavior
The second query (with null in its key) should be invalidated and refetched.
Actual behavior
Nothing happens — the query is not invalidated or refetched.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: macOS Sequoia Version 15.5 (24F74)
- Browser: Chrome
- Version: 138.0.7204.101 (Official Build) (arm64)
Tanstack Query adapter
react-query
TanStack Query version
5.83.0
TypeScript version
4.4.4
Additional context
I suspected the issue might be related to how react-query serializes keys internally (e.g., via JSON.stringify). However, even if:
undefined is converted to null, both keys would be equivalent, and invalidation should still work (case 2 in CodeSandbox example).
undefined is omitted or transformed into a different form, keys should remain distinct and not interfere with each other (case 3 in CodeSandbox example).
Describe the bug
When a disabled query is registered with
undefinedin itsqueryKey, invalidation stops working for other queries that havenullin the same key position.This behavior is unexpected, since
nullandundefinedshould not be treated as equivalent or conflicting in this context.Your minimal, reproducible example
https://codesandbox.io/p/sandbox/s3fw8s
Steps to reproduce
undefinedin the key:nullin the key:Expected behavior
The second query (with
nullin its key) should be invalidated and refetched.Actual behavior
Nothing happens — the query is not invalidated or refetched.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Tanstack Query adapter
react-query
TanStack Query version
5.83.0
TypeScript version
4.4.4
Additional context
I suspected the issue might be related to how react-query serializes keys internally (e.g., via
JSON.stringify). However, even if:undefinedis converted tonull, both keys would be equivalent, and invalidation should still work (case 2 in CodeSandbox example).undefinedis omitted or transformed into a different form, keys should remain distinct and not interfere with each other (case 3 in CodeSandbox example).