Skip to content

Commit 2766d05

Browse files
committed
ref: Don't mutate the queryRef here (let it be done in the emitter listeners)
1 parent 93f1b65 commit 2766d05

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

packages/nuqs/src/useQueryState.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export function useQueryState<T = string>(
282282
) {
283283
newValue = null
284284
}
285-
queryRef.current = enqueueQueryStringUpdate(key, newValue, serialize, {
285+
const query = enqueueQueryStringUpdate(key, newValue, serialize, {
286286
// Call-level options take precedence over hook declaration options.
287287
history: options.history ?? history,
288288
shallow: options.shallow ?? shallow,
@@ -291,7 +291,7 @@ export function useQueryState<T = string>(
291291
startTransition: options.startTransition ?? startTransition
292292
})
293293
// Sync all hooks state (including this one)
294-
emitter.emit(key, { state: newValue, query: queryRef.current })
294+
emitter.emit(key, { state: newValue, query })
295295
return scheduleFlushToURL(adapter)
296296
},
297297
[key, history, shallow, scroll, throttleMs, startTransition, adapter]

packages/nuqs/src/useQueryStates.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ export function useQueryStates<KeyMap extends UseQueryStatesKeysMap>(
209209
) {
210210
value = null
211211
}
212-
213-
queryRef.current[urlKey] = enqueueQueryStringUpdate(
212+
const query = enqueueQueryStringUpdate(
214213
urlKey,
215214
value,
216215
parser.serialize ?? String,
@@ -228,10 +227,7 @@ export function useQueryStates<KeyMap extends UseQueryStatesKeysMap>(
228227
startTransition
229228
}
230229
)
231-
emitter.emit(urlKey, {
232-
state: value,
233-
query: queryRef.current[urlKey] ?? null
234-
})
230+
emitter.emit(urlKey, { state: value, query })
235231
}
236232
return scheduleFlushToURL(adapter)
237233
},

0 commit comments

Comments
 (0)