File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -238,6 +238,39 @@ function defineTest(f: Fixture) {
238238 await testUseActionState ( page )
239239 } )
240240
241+ test ( 'useActionState nojs to js' , async ( { page } ) => {
242+ // this test fails without `formState` passed to `hydrateRoot(..., { formState })`
243+
244+ // intercept request to disable js
245+ let js : boolean
246+ await page . route ( f . url ( ) , async ( route ) => {
247+ if ( ! js ) {
248+ await route . continue ( { url : route . request ( ) . url ( ) + '?__nojs' } )
249+ return
250+ }
251+ await route . continue ( )
252+ } )
253+
254+ // no js
255+ js = false
256+ await page . goto ( f . url ( ) )
257+ await expect ( page . getByTestId ( 'use-action-state' ) ) . toContainText (
258+ 'test-useActionState: 0' ,
259+ )
260+ await page . getByTestId ( 'use-action-state' ) . click ( )
261+ await expect ( page . getByTestId ( 'use-action-state' ) ) . toContainText (
262+ 'test-useActionState: 1' ,
263+ )
264+
265+ // with js (hydration)
266+ js = true
267+ await page . getByTestId ( 'use-action-state' ) . click ( )
268+ await waitForHydration ( page )
269+ await expect ( page . getByTestId ( 'use-action-state' ) ) . toContainText (
270+ 'test-useActionState: 2' , // this becomes "0" without formState
271+ )
272+ } )
273+
241274 async function testUseActionState ( page : Page ) {
242275 await expect ( page . getByTestId ( 'use-action-state' ) ) . toContainText (
243276 'test-useActionState: 0' ,
You can’t perform that action at this time.
0 commit comments