Skip to content

Commit

Permalink
fix: 14.0.3 WHS support for useQueryStates
Browse files Browse the repository at this point in the history
14.0.3 WHS doesn't have the sync mechanism in place,
so it's replaced by this effect. It will be removed in v2.
  • Loading branch information
franky47 committed Sep 5, 2024
1 parent 40cb98d commit 5c6fc39
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/nuqs/src/useQueryStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ export function useQueryStates<KeyMap extends UseQueryStatesKeysMap>(
initialSearchParams
)

React.useEffect(() => {
// This will be removed in v2 which will drop support for
// partially-functional shallow routing (14.0.2 and 14.0.3)
if (window.next?.version !== '14.0.3') {
return
}
const state = parseMap(
keyMap,
initialSearchParams,
queryRef.current,
stateRef.current
)
setInternalState(state)
}, [
Object.keys(keyMap)
.map(key => initialSearchParams?.get(key))
.join('&'),
keys
])

// Sync all hooks together & with external URL changes
React.useInsertionEffect(() => {
function updateInternalState(state: V) {
Expand Down

0 comments on commit 5c6fc39

Please sign in to comment.