File tree 2 files changed +19
-7
lines changed
2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change 1
1
import { createElement , type ReactNode } from 'react'
2
+ import { resetQueue } from '../update-queue'
2
3
import { renderQueryString } from '../url-encoding'
3
4
import type { AdapterInterface , AdapterOptions } from './defs'
4
5
import { context } from './internal.context'
@@ -15,10 +16,17 @@ type TestingAdapterProps = {
15
16
searchParams ?: string | Record < string , string > | URLSearchParams
16
17
onUrlUpdate ?: OnUrlUpdateFunction
17
18
rateLimitFactor ?: number
19
+ resetUrlUpdateQueueOnMount ?: boolean
18
20
children : ReactNode
19
21
}
20
22
21
- export function NuqsTestingAdapter ( props : TestingAdapterProps ) {
23
+ export function NuqsTestingAdapter ( {
24
+ resetUrlUpdateQueueOnMount = true ,
25
+ ...props
26
+ } : TestingAdapterProps ) {
27
+ if ( resetUrlUpdateQueueOnMount ) {
28
+ resetQueue ( )
29
+ }
22
30
const useAdapter = ( ) : AdapterInterface => ( {
23
31
searchParams : new URLSearchParams ( props . searchParams ) ,
24
32
updateUrl ( search , options ) {
Original file line number Diff line number Diff line change @@ -25,6 +25,15 @@ export function getQueuedValue(key: string) {
25
25
return updateQueue . get ( key )
26
26
}
27
27
28
+ export function resetQueue ( ) {
29
+ updateQueue . clear ( )
30
+ transitionsQueue . clear ( )
31
+ queueOptions . history = 'replace'
32
+ queueOptions . scroll = false
33
+ queueOptions . shallow = true
34
+ queueOptions . throttleMs = FLUSH_RATE_LIMIT_MS
35
+ }
36
+
28
37
export function enqueueQueryStringUpdate < Value > (
29
38
key : string ,
30
39
value : Value | null ,
@@ -132,12 +141,7 @@ function flushUpdateQueue(
132
141
const options = { ...queueOptions }
133
142
const transitions = Array . from ( transitionsQueue )
134
143
// Restore defaults
135
- updateQueue . clear ( )
136
- transitionsQueue . clear ( )
137
- queueOptions . history = 'replace'
138
- queueOptions . scroll = false
139
- queueOptions . shallow = true
140
- queueOptions . throttleMs = FLUSH_RATE_LIMIT_MS
144
+ resetQueue ( )
141
145
debug ( '[nuqs queue] Flushing queue %O with options %O' , items , options )
142
146
for ( const [ key , value ] of items ) {
143
147
if ( value === null ) {
You can’t perform that action at this time.
0 commit comments