-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Description
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 tonull
, 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).
glebArkhipov
Metadata
Metadata
Assignees
Labels
No labels