Skip to content

Update form documentation for forms default reset behavior - #8512

Merged
aurorascharff merged 29 commits into
reactjs:mainfrom
MaxwellCohen:feat/8397/disabling-default-form-reset
Nov 5, 2026
Merged

aurorascharff merged 29 commits into
reactjs:mainfrom
MaxwellCohen:feat/8397/disabling-default-form-reset

Conversation

@MaxwellCohen

Copy link
Copy Markdown
Contributor

Summary

Documents React’s default form-reset behavior when using the function action / formAction props, and explains how to preserve field values when you don’t want that reset. Applying @rickhanlonii's feedback from #7795 and building off of work @aurorascharff recentlly did.

  • Adds default reset behavior in Caveats, the action prop section, and a new Troubleshooting entry (“Why does my form reset when I use an action?”). React resets uncontrolled fields after a successful action, matching browser <form action="..."> behavior (including before JS loads).
  • Adds “Preserve form values after submission” with a Sandpack example: call e.preventDefault() in onSubmit, then run the action manually inside useTransition while keeping the action prop for progressive enhancement.
  • Adds a DeepDive for finer control: requestFormReset from react-dom, and returning submitted FormData from server actions to restore values via defaultValue (with useActionState).
  • Updates the multiple-submission-types example to a draft/publish scenario that shows how controlled state and key/defaultValue keep textarea content after “Save draft.”

Closes #8397

Alternative to #7795 and #8465

@github-actions

Copy link
Copy Markdown

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@MaxwellCohen
MaxwellCohen marked this pull request as ready for review June 29, 2026 19:09
@aurorascharff

Copy link
Copy Markdown
Collaborator

Going to dig a bit into the current behavior of this, so might take some time to review! Thank you!

@aurorascharff
aurorascharff requested a review from gaearon July 1, 2026 17:21
…ction` prop and its behavior:

- including the handling of `FormData`,
- the necessity of `name` attributes,
- the advantages of using a function over a URL.
- removed redundant information about `e.preventDefault()` for the `action` prop.
function EditForm() {
// The action returns { submitted: formData, error } on failure
const [state, formAction] = useActionState(submitForm, {});
const values = state.submitted ?? new FormData();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a seperate variable for values? Is this pattern better than returning the values from the useActionState function?

https://aurorascharff.no/posts/handling-form-validation-errors-and-resets-with-useactionstate/
https://www.robinwieruch.de/react-server-action-reset-form/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I forgot about optional chaining (one of my favorite JS features when working on making the examples)

…s in the `action` prop, including detailed examples for passing extra data and handling form submissions. Clarify the behavior of form elements and their interaction with `FormData`.

@samselikoff samselikoff left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely need a Learn for all this but I think this is still an improvement on the current page! Just a few comments

aurorascharff added a commit that referenced this pull request Nov 4, 2026
…8538)

* Fix Server Functions documentation examples

* Fix code snippet highlights

Corrected the index of 'submitAction' in the code snippet.

* Clarify wording

* Update section titles for clarity

* Polish Server Functions examples: consistent headings, reset wording, transition comment

- Convert the remaining two Usage headings to gerund form to match the
  rest of the page and react.dev convention (anchors unchanged)
- Reset wording: "succeeds" + "the form's uncontrolled fields" (aligns with #8512)
- Comment the startTransition-after-await; bump CodeStep line accordingly

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Polish Server Functions examples

* Fix Server Functions code highlight

---------

Co-authored-by: Aurora Scharff <aurora.sofie@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@karlhorky

karlhorky commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

@MaxwellCohen @samselikoff @aurorascharff Thanks for getting this in!

Did this also cover the current open bugs in React with <select> and <input type="checkbox" /> when using actions and Controlled Components?

These are super confusing, especially to new learners and LLMs.

@aurorascharff

aurorascharff commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

@MaxwellCohen @samselikoff @aurorascharff Thanks for getting this in!

Did this also cover the current open bugs in React with <select> and <input type="checkbox" /> when using actions and Controlled Components?

These are super confusing, especially to new learners and LLMs.

I will dig into this!

@karlhorky

  • I checked with the team, and there’s no plan to leave these unfixed.
  • The fixes are more complex than they look and need careful verification across browsers.
  • It’s a matter of balancing that work with other priorities.

This branch was successfully deployed

1 active deployment
Preview — 7dd9e907 Deployed Nov 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Suggestion]: improve <Form> documentation to explain how to keep form state after submission

6 participants