Skip to content

Commit 4d85cf9

Browse files
committed
fix: always compare query keys as arrays
1 parent 8c40ea5 commit 4d85cf9

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/core/tests/queryCache.test.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,14 +822,17 @@ describe('queryCache', () => {
822822
await testClient.prefetchQuery(key1, () => 'data1')
823823
await testClient.prefetchQuery(key2, () => 'data2')
824824
await testClient.prefetchQuery([{ a: 'a', b: 'b' }], () => 'data3')
825+
await testClient.prefetchQuery(['posts', 1], () => 'data4')
825826
testClient.invalidateQueries(key2)
826827
const query1 = testCache.find(key1)!
827828
const query2 = testCache.find(key2)!
828829
const query3 = testCache.find([{ a: 'a', b: 'b' }])!
830+
const query4 = testCache.find(['posts', 1])!
829831

830832
expect(testCache.findAll(key1)).toEqual([query1])
831-
expect(testCache.findAll()).toEqual([query1, query2, query3])
832-
expect(testCache.findAll({})).toEqual([query1, query2, query3])
833+
expect(testCache.findAll([key1])).toEqual([query1])
834+
expect(testCache.findAll()).toEqual([query1, query2, query3, query4])
835+
expect(testCache.findAll({})).toEqual([query1, query2, query3, query4])
833836
expect(testCache.findAll(key1, { active: false })).toEqual([query1])
834837
expect(testCache.findAll(key1, { active: true })).toEqual([])
835838
expect(testCache.findAll(key1, { stale: true })).toEqual([])
@@ -869,6 +872,7 @@ describe('queryCache', () => {
869872
expect(
870873
testCache.findAll({ predicate: query => query === query3 })
871874
).toEqual([query3])
875+
expect(testCache.findAll('posts')).toEqual([query4])
872876
})
873877

874878
test('query interval is cleared when unsubscribed to a refetchInterval query', async () => {

src/core/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ export function matchQuery(
170170
if (query.queryHash !== hashFn(queryKey)) {
171171
return false
172172
}
173-
} else if (!partialDeepEqual(query.queryKey, queryKey)) {
173+
} else if (
174+
!partialDeepEqual(ensureArray(query.queryKey), ensureArray(queryKey))
175+
) {
174176
return false
175177
}
176178
}

0 commit comments

Comments
 (0)