docs: explain how to preserve form state after submission#8465
Open
rylansedlacek wants to merge 1 commit into
Open
docs: explain how to preserve form state after submission#8465rylansedlacek wants to merge 1 commit into
rylansedlacek wants to merge 1 commit into
Conversation
Size changesDetails📦 Next.js Bundle Analysis for react-devThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
MaxwellCohen
reviewed
Jun 2, 2026
MaxwellCohen
left a comment
There was a problem hiding this comment.
Thank you very much for taking an attempt at the issue.
I noticed an inaccuracy with the help text. Forms by default reset, because they refresh the pages or go to another page on submission.
Also, a missing example/section of using actions and useActionState to keep state like this: https://codesandbox.io/p/sandbox/react-dev-forked-3ptf98
|
|
||
| </Sandpack> | ||
|
|
||
| Using `onSubmit` preserves the browser's default behavior of leaving form values unchanged after submission while still allowing the submission logic to run in a Transition. |
There was a problem hiding this comment.
This line is incorrect because HTML forms, by default, reset the page/form. We can see it at the event.preventDefault(); in line 94
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Form page now explains how to preserve form state after submission when using forms.
In the issue it was mentioned that uncontrolled fields are reset after successful actions, but there is no explanation on how to opt out of that behavior.
This change adds a new section demonstrating how to use
onSubmittogether withstartTransitionto preserve form values while still using transitions.Resolves #8397