Skip to content

Commit 5c6fc39

Browse files
committed
fix: 14.0.3 WHS support for useQueryStates
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.
1 parent 40cb98d commit 5c6fc39

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/nuqs/src/useQueryStates.ts

+20
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@ export function useQueryStates<KeyMap extends UseQueryStatesKeysMap>(
8888
initialSearchParams
8989
)
9090

91+
React.useEffect(() => {
92+
// This will be removed in v2 which will drop support for
93+
// partially-functional shallow routing (14.0.2 and 14.0.3)
94+
if (window.next?.version !== '14.0.3') {
95+
return
96+
}
97+
const state = parseMap(
98+
keyMap,
99+
initialSearchParams,
100+
queryRef.current,
101+
stateRef.current
102+
)
103+
setInternalState(state)
104+
}, [
105+
Object.keys(keyMap)
106+
.map(key => initialSearchParams?.get(key))
107+
.join('&'),
108+
keys
109+
])
110+
91111
// Sync all hooks together & with external URL changes
92112
React.useInsertionEffect(() => {
93113
function updateInternalState(state: V) {

0 commit comments

Comments
 (0)