Skip to content

[react-dom] Preserve controlled <select> value on automatic form reset - #38447

Open
SandeepDirishala wants to merge 2 commits into
react:mainfrom
SandeepDirishala:fix-controlled-select-form-reset
Open

SandeepDirishala wants to merge 2 commits into
react:mainfrom
SandeepDirishala:fix-controlled-select-form-reset

Conversation

@SandeepDirishala

Copy link
Copy Markdown

Summary

Fixes #30580.

After a form action completes, React calls requestFormReset, which performs a native form.reset(). React's design assumes DOM defaults already track controlled props — as the comment in ReactFiberCommitWork puts it, the reset is deferred until after all other mutations "so that defaultValue will already be updated."

<input> and <textarea> uphold that by mirroring their controlled value into node.defaultValue. <select> can't: its selection lives on the options, and the controlled path in updateSelect/initSelect passes setDefaultSelected: false, so option.defaultSelected never tracks the React value.

So after the reset the select displays its DOM default (the first non-disabled option) while the fiber still holds the previous memoizedProps.value. The next render diffs clean, nothing repairs the DOM, and the controlled component stays desynced from its props permanently. There is no fallback either: no plugin registers reset with the controlled-state restore queue, so the existing restoreControlledState is unreachable on this path.

This reapplies controlled state from the current props once the native reset has run. It is a no-op for <input> and <textarea>, whose defaults already match their props, and for uncontrolled elements, since updateInput only touches node.value when props.value != null — uncontrolled fields still reset normally.

How did you test this?

Added preserves a controlled select on automatic form reset to ReactDOMForm-test.js. It fails on main:

expect(received).toEqual(expected)

Expected: "sebbie"
Received: "acdlite"

and passes with the fix.

Also ran ReactDOMForm-test, ReactDOMSelect-test, ReactDOMInput-test and ReactDOMTextarea-test together (284 passed, 0 failed), plus yarn lint and a prettier check on the changed files.

Worth noting that ReactDOMForm-test.js previously had six automatic-reset tests, all using <input>; <select> did not appear in the file at all.

After a form action completes, React performs a native form.reset(). That
relies on DOM defaults already tracking controlled props: <input> and
<textarea> mirror their value into defaultValue, but <select> keeps its
selection on the options and passes setDefaultSelected: false on the
controlled path, so option.defaultSelected never tracks the React value.

After the reset the select shows its DOM default while the fiber still holds
the previous memoizedProps.value, so the next render diffs clean and the DOM
is left out of sync for good.

Reapply controlled state from the current props once the native reset has
run. This is a no-op for <input> and <textarea>, whose defaults already
match, and for uncontrolled elements, which updateInput leaves alone when
props.value is null.

Fixes react#30580
@meta-cla

meta-cla Bot commented Nov 29, 2026

Copy link
Copy Markdown

Hi @SandeepDirishala!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

A size report will appear here when the build finishes.

Generated by sizebot against f1e304a

@meta-cla

meta-cla Bot commented Nov 29, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed label Nov 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[React 19] Controlled <select> component is subject to automatic form reset

1 participant