-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Description
Describe the bug
There is a bug in the returned value of useQueries
when there are duplicate, unsorted queries, such as useQueries([ { queryKey: ['A'] }, { queryKey: ['B'] }, { queryKey: ['A'] }]
. The current code returns [ QueryResult<'A'>, QueryResult<'A'>, QueryResult<'B'> ]
.
The root cause is due to a bug introduced here in the QueriesObserver
's #findMatchingObservers
method, where we always sort the results based on the queryHash.
Your minimal, reproducible example
https://codesandbox.io/p/sandbox/dreamy-matsumoto-mc8jtm
Steps to reproduce
- Create a useQueries call with duplicate queries (same queryKey / queryKeyHash) in an unsorted order.
- Inspect the result of useQueries to see they don't match with the input array
Another way to reproduce is through the unit test written in this pull request #8351
Expected behavior
We expect the input (Array) to #findMatchingObservers to match the output (Array)
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
This affects all operating systems/browsers
Tanstack Query adapter
None
TanStack Query version
5.59.6
TypeScript version
No response
Additional context
No response
etlovett
Metadata
Metadata
Assignees
Labels
No labels