Skip to content

[DOM] Keep controlled checkbox and radio state on form reset - #37668

Open
zxuhan wants to merge 1 commit into
react:mainfrom
zxuhan:fix-controlled-checkbox-form-reset
Open

zxuhan wants to merge 1 commit into
react:mainfrom
zxuhan:fix-controlled-checkbox-form-reset

Conversation

@zxuhan

@zxuhan zxuhan commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The HTML form reset algorithm restores a checkbox or radio from its checked content attribute, i.e. defaultChecked. React stops updating that attribute after mount, so a controlled input is reset as if it were uncontrolled, both by form.reset() and by the automatic reset that runs after a form action:

const [checked, setChecked] = useState(false);

<form action={myAction}>
  {/* checked by the user, then silently unchecked once the action completes */}
  <input type="checkbox" checked={checked} onChange={e => setChecked(e.target.checked)} />
  <button>Submit</button>
</form>

updateInput already keeps the value attribute in sync with the value prop for exactly this reason, and initInput writes the checked attribute from the checked prop on mount. Only the update path was missing, so a controlled checkbox reverts to whatever it rendered with initially while a controlled text input in the same form keeps its value.

This applies the cascade the checked property already uses to the attribute as well, guarded against redundant writes the way setDefaultValue is. disableInputAttributeSyncing is unchanged: in that mode the attribute stays driven solely by defaultChecked.

<select> has the same problem and is fixed separately in #35168.

Fixes #31695

How did you test this change?

One test per file, both failing on main. In ReactDOMInput-test.js, a controlled checkbox and radio keep their checkedness across form.reset() both when going unchecked to checked and back, while an uncontrolled checkbox in the same form is still reset. In ReactDOMForm-test.js, the automatic reset that runs after a form action no longer clears them.

  • yarn test and yarn test --prod on packages/react-dom
  • yarn test-stable, yarn test-www, yarn test-www --variant=false, yarn test-classic, yarn test-classic --variant=false on the touched suites
  • yarn test (full suite)
  • yarn linc
  • yarn prettier-check
  • yarn flow dom-node and yarn flow dom-browser

@meta-cla meta-cla Bot added the CLA Signed label Sep 21, 2026
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Comparing: 59aff3e...180acbe

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 = 7.35 kB 7.35 kB -0.10% 1.96 kB 1.96 kB
oss-stable/react-dom/cjs/react-dom-client.production.js +0.03% 625.86 kB 626.04 kB +0.03% 110.60 kB 110.63 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 7.36 kB 7.36 kB -0.05% 1.96 kB 1.96 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.03% 697.07 kB 697.26 kB +0.03% 122.04 kB 122.08 kB
facebook-www/ReactDOM-prod.classic.js +0.03% 715.84 kB 716.02 kB +0.03% 125.27 kB 125.30 kB
facebook-www/ReactDOM-prod.modern.js +0.03% 706.15 kB 706.34 kB +0.03% 123.70 kB 123.73 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by sizebot against 180acbe

@zxuhan

zxuhan commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

hi @eps1lon would you also take a look at this when you have a moment? thanks for reviewing!

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 checkboxes are reset by form submission and form.reset()

1 participant