File tree Expand file tree Collapse file tree 3 files changed +49
-1
lines changed Expand file tree Collapse file tree 3 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -53,5 +53,21 @@ createNextDescribe(
5353 return browser . elementByCss ( '#hydrated' ) . text ( )
5454 } , 'hydrated' )
5555 } )
56+
57+ it ( 'should send the action to the provided permalink with form state when JS disabled' , async ( ) => {
58+ const browser = await next . browser ( '/client/form-state/page-2' , {
59+ disableJavaScript : true ,
60+ } )
61+
62+ // Simulate a progressively enhanced form request
63+ await browser . eval (
64+ `document.getElementById('name-input').value = 'test-permalink'`
65+ )
66+ await browser . eval ( `document.getElementById('form-state-form').submit()` )
67+
68+ await check ( ( ) => {
69+ return browser . elementByCss ( '#form-state' ) . text ( )
70+ } , 'initial-state:test-permalink' )
71+ } )
5672 }
5773)
Original file line number Diff line number Diff line change 1+ 'use client'
2+
3+ import { experimental_useFormState } from 'react-dom'
4+ import { appendName } from '../actions'
5+ import { useEffect , useState } from 'react'
6+
7+ export default function Page ( ) {
8+ const [ state , appendNameFormAction ] = experimental_useFormState (
9+ appendName ,
10+ 'initial-state' ,
11+ '/client/form-state'
12+ )
13+
14+ const [ hydrated , setHydrated ] = useState ( false )
15+ useEffect ( ( ) => {
16+ setHydrated ( true )
17+ } , [ ] )
18+
19+ return (
20+ < >
21+ < form id = "form-state-form" action = { appendNameFormAction } >
22+ < p id = "form-state" > { state } </ p >
23+ < input id = "name-input" name = "name" />
24+ < button id = "submit-form" type = "submit" >
25+ log
26+ </ button >
27+ </ form >
28+ { hydrated ? < p id = "hydrated" > hydrated</ p > : null }
29+ </ >
30+ )
31+ }
Original file line number Diff line number Diff line change @@ -7,7 +7,8 @@ import { useEffect, useState } from 'react'
77export default function Page ( ) {
88 const [ state , appendNameFormAction ] = experimental_useFormState (
99 appendName ,
10- 'initial-state'
10+ 'initial-state' ,
11+ '/client/form-state'
1112 )
1213
1314 const [ hydrated , setHydrated ] = useState ( false )
You can’t perform that action at this time.
0 commit comments