Query keys with object property set to undefined are not considered equal to missing property during invalidation
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 50.3k
- Forks
- 4.2k
- Avg merge
- 18h 25m
- Merged PRs (30d)
- 200
Description
Describe the bug
Query keys with object property set to undefined are not considered equal to missing property. Based on the docs, it should be the same: https://react-query.tanstack.com/guides/query-keys#query-keys-are-hashed-deterministically
Your minimal, reproducible example
https://codesandbox.io/s/react-query-trz8sx?file=/src/App.tsx
Steps to reproduce
- Open the codesandbox link
- Show codesandbox console
- There are two queries rendered, the first fetch all items, and the second fetch filtered ones.
- You can see two buttons with invalidation hooks. The first one invalidates both queries, the second one invalidates only non-filtered results. See the console for refetch logs.
Expected behavior
I expect both keys should invalidate the same records no matter of filter: undefined as mentioned in react-query docs.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
macOS v12.4
Chrome 103
react-query version
Both v3.39.1 and v4.0.0-beta.23
TypeScript version
v4.7.3
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked CodeSandbox reproduction and compare the documented deterministic query-key behavior with the invalidation results for missing and undefined object properties. Trace the query-key hashing and invalidation entry points, then verify that both queries invalidate the same records in the reproduction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100