-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Form error with server action on route change #67974
Comments
Hello, Do you need to use both action and onSubmit at the same place (inside ) ?. if not then you can use the onSubmit and remove the formAction and use formAction inside your onSumbit button. Which works perfectly. Though you have to make some changes to your FormData type as it is not compatible with native FormData type.If you still want to use action inside form, let me know.Also check your pull requests. |
It would be really appreciated if the issue is closed after resolution. ; ) |
Sorry, thought I closed it already my bad |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Link to the code that reproduces this issue
https://github.com/riacoding/formbug
To Reproduce
javascript:throw new Error('A React form was unexpectedly submitted. If you called form.submit() manually, consider using form.requestSubmit() instead. If you\'re trying to use event.stopPropagation() in a submit event handler, consider also calling event.preventDefault().')
Current vs. Expected behavior
I would expect that the action attribute would not have the error message. I believe that Nextjs is injecting some attributes and some hidden form elements into the form. This does not appear to happen on a route change and only happens on a full page refresh. If the elements are not there the form will error on submit. The happens both with just the form action and with form action and onSubmit handlers.
Provide environment information
Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020 Available memory (MB): 98304 Available CPU cores: 12 Binaries: Node: 20.5.0 npm: 9.8.0 Yarn: N/A pnpm: N/A Relevant Packages: next: 14.2.5 // Latest available version is detected (14.2.5). eslint-config-next: 14.2.5 react: 18.3.1 react-dom: 18.3.1 typescript: 5.5.3 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
This was in the production release 14.2.5. It is also integrating React Hook Form for client side validation with zod. Steps to reproduce in the sample repo as well FormBug Repo
The text was updated successfully, but these errors were encountered: