Skip to content

[react-dom] Keep controlled <select> value on form reset - #35168

Open
eps1lon wants to merge 3 commits into
react:mainfrom
eps1lon:sebbie/controlled-select
Open

eps1lon wants to merge 3 commits into
react:mainfrom
eps1lon:sebbie/controlled-select

Conversation

@eps1lon

@eps1lon eps1lon commented Nov 18, 2025 •

Copy link
Copy Markdown
Collaborator

Closes #30580
Closes #34295

React's automatic form reset made it more apparent that controlled select is not working with form.reset(). Each form associated element has its own reset algorithm.

For <input>, that's reading back the value attribute which is why syncing the attribute value is critical for reset.

According to the spec, <select> reads from the selected attribute (https://html.spec.whatwg.org/multipage/form-elements.html#the-select-element) which is reflected from the defaultSelected DOM property. I adjusted the warning for setting selected via prop to make it clear why doing that is problematic.

Test plan

@meta-cla meta-cla Bot added the CLA Signed label Nov 18, 2025
@github-actions github-actions Bot added the React Core Team Opened by a member of the React Core Team label Nov 18, 2025
@react-sizebot

react-sizebot commented Nov 18, 2025 •

Copy link
Copy Markdown

Comparing: 0972e23...cacd6ba

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB = 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js +0.03% 608.16 kB 608.32 kB +0.03% 107.65 kB 107.68 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.02% 666.18 kB 666.34 kB +0.03% 117.35 kB 117.39 kB
facebook-www/ReactDOM-prod.classic.js +0.02% 693.31 kB 693.47 kB +0.03% 121.98 kB 122.01 kB
facebook-www/ReactDOM-prod.modern.js +0.02% 683.73 kB 683.90 kB +0.03% 120.36 kB 120.40 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
test_utils/ReactAllWarnings.js +0.22% 66.51 kB 66.66 kB +0.12% 16.74 kB 16.76 kB

Generated by 🚫 dangerJS against cacd6ba

@eps1lon eps1lon changed the title Add fixture [react-dom] Keep controlled <select> value on form reset Nov 18, 2025
@eps1lon eps1lon changed the title [react-dom] Keep controlled <select> value on form reset [react-dom] Keep controlled <select> value on form reset Nov 18, 2025
@eps1lon
eps1lon marked this pull request as ready for review November 18, 2025 14:50
@eps1lon
eps1lon force-pushed the sebbie/controlled-select branch from 05867ea to cacd6ba Compare November 18, 2025 16:04
@billyjanitsch

Copy link
Copy Markdown
Contributor

@eps1lon thanks for this PR. I'm glad to see this fixed!

Checkboxes and radio inputs are also affected. (See #31695.) Would it be straightforward to fix them in the same way?

@eps1lon

eps1lon commented Nov 19, 2025

Copy link
Copy Markdown
Collaborator Author

I'll follow-up with that once this is merged.

@stefanprobst

Copy link
Copy Markdown

@eps1lon what's the status of this?

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

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants