@@ -17,6 +17,7 @@ import { emitter, type CrossHookSyncPayload } from './lib/sync'
1717import { type Parser } from './parsers'
1818import { isAbsentFromUrl } from './lib/search-params'
1919import { safeParse } from './lib/safe-parse'
20+ import { compareQuery } from './lib/compare'
2021
2122type KeyMapValue < Type > = Parser < Type > &
2223 Options & {
@@ -385,14 +386,18 @@ function parseMap<KeyMap extends UseQueryStatesKeysMap>(
385386 const state = Object . entries ( keyMap ) . reduce ( ( out , [ stateKey , parser ] ) => {
386387 const urlKey = urlKeys ?. [ stateKey ] ?? stateKey
387388 const queuedQuery = queuedQueries [ urlKey ]
389+ const defaultValue = parser . type === 'multi' ? [ ] : null
388390 const query =
389391 queuedQuery === undefined
390- ? parser . type === 'multi'
391- ? ( searchParams ?. getAll ( urlKey ) ?? [ ] )
392- : ( searchParams ?. get ( urlKey ) ?? null )
392+ ? ( ( parser . type === 'multi'
393+ ? searchParams ?. getAll ( urlKey )
394+ : searchParams ?. get ( urlKey ) ) ?? defaultValue )
393395 : queuedQuery
394- // todo this === comparison likely won't work with arrays
395- if ( cachedQuery && cachedState && ( cachedQuery [ urlKey ] ?? null ) === query ) {
396+ if (
397+ cachedQuery &&
398+ cachedState &&
399+ compareQuery ( cachedQuery [ urlKey ] ?? defaultValue , query )
400+ ) {
396401 // Cache hit
397402 out [ stateKey as keyof KeyMap ] = cachedState [ stateKey ] ?? null
398403 return out
0 commit comments