Skip to content

Commit 3d48c05

Browse files
committed
test: Add failing test for repro 760
1 parent 3017660 commit 3d48c05

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference types="cypress" />
2+
3+
describe('repro-760', () => {
4+
it('supports dynamic default values', () => {
5+
cy.visit('/app/repro-760')
6+
cy.contains('#hydration-marker', 'hydrated').should('be.hidden')
7+
cy.get('#value-a').should('have.text', 'a')
8+
cy.get('#value-b').should('have.text', 'b')
9+
cy.get('#trigger-a').click()
10+
cy.get('#trigger-b').click()
11+
cy.get('#value-a').should('have.text', 'pass')
12+
cy.get('#value-b').should('have.text', 'pass')
13+
})
14+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use client'
2+
3+
import { parseAsString, useQueryState, useQueryStates } from 'nuqs'
4+
import { Suspense, useState } from 'react'
5+
6+
export default function Page() {
7+
return (
8+
<Suspense>
9+
<DynamicUseQueryState />
10+
<DynamicUseQueryStates />
11+
</Suspense>
12+
)
13+
}
14+
15+
function DynamicUseQueryState() {
16+
const [defaultValue, setDefaultValue] = useState('a')
17+
const [value] = useQueryState('a', parseAsString.withDefault(defaultValue))
18+
return (
19+
<section>
20+
<button id="trigger-a" onClick={() => setDefaultValue('pass')}>
21+
Trigger
22+
</button>
23+
<span id="value-a">{value}</span>
24+
</section>
25+
)
26+
}
27+
28+
function DynamicUseQueryStates() {
29+
const [defaultValue, setDefaultValue] = useState('b')
30+
const [{ value }] = useQueryStates(
31+
{
32+
value: parseAsString.withDefault(defaultValue)
33+
},
34+
{ urlKeys: { value: 'b' } }
35+
)
36+
return (
37+
<section>
38+
<button id="trigger-b" onClick={() => setDefaultValue('pass')}>
39+
Trigger
40+
</button>
41+
<span id="value-b">{value}</span>
42+
</section>
43+
)
44+
}

0 commit comments

Comments
 (0)