Skip to content

Conversation

@rdanciu11
Copy link

@rdanciu11 rdanciu11 commented Dec 15, 2025

Summary

Fixes controlled form inputs incorrectly resetting after form submission with form actions.

Fixes

The Bug

When a form with a function action is submitted, controlled form inputs (those with checked or value props) are incorrectly reset to their default values. This breaks the expected behavior where controlled inputs should maintain their state.

Affected input types:

  • Text inputs (<input type="text">)
  • Select elements (<select>)
  • Textareas (<textarea>)
  • Checkboxes (<input type="checkbox">)
  • Radio buttons (<input type="radio">)

The Fix

Enhanced resetFormInstance() in ReactFiberConfigDOM.js to:

  1. Check React's internal fiber tree to determine if an input is controlled
  2. Examine memoizedProps for control props:
    • value prop for text inputs, select elements, and textareas
    • checked prop for checkboxes and radio buttons
  3. Skip reset for controlled inputs
  4. Only reset truly uncontrolled inputs

This ensures controlled inputs maintain their state after form submission while uncontrolled inputs still reset as expected.

Tests

Added comprehensive test coverage in ReactDOMForm-test.js:

Controlled inputs (should NOT reset):

  • Controlled checkboxes don't reset on form submission
  • Controlled radio buttons don't reset on form submission
  • Controlled select elements don't reset on form submission
  • Controlled textarea elements don't reset on form submission

Uncontrolled inputs (should still reset):

  • Uncontrolled checkboxes still reset correctly
  • Uncontrolled select elements still reset correctly
  • Uncontrolled textarea elements still reset correctly

All existing tests continue to pass

How Has This Been Tested?

  • Ran full test suite: yarn test ReactDOMForm-test
  • Verified reproduction case scenarios
  • Tested with both controlled and uncontrolled inputs across all affected input types

@meta-cla meta-cla bot added the CLA Signed label Dec 15, 2025
@rdanciu11 rdanciu11 marked this pull request as draft December 15, 2025 01:51
@rdanciu11 rdanciu11 marked this pull request as ready for review December 15, 2025 02:04
@albr74
Copy link

albr74 commented Dec 19, 2025

Hi @rdanciu11 There is a bug "similar" to this #30580
Please, can you see it?. Perhaps the solution is similar to your approach.

@rdanciu11
Copy link
Author

Hi @albr74. Actually, my implementation should already take care of that too because it checks React's fiber tree for control props (value or checked) rather than targeting specific element types.

I will write some tests right now to make sure.

I wasn't aware of issue #30580. Thanks for the heads up.

Forms were incorrectly being reset even when form actions threw errors.
This was because requestFormReset was called before the action executed.

Now requestFormReset is only called if the action completes without
throwing a synchronous error. For async actions, the form reset is
scheduled immediately after the action is called (before it resolves),
which is the correct behavior.

Added test to verify forms remain dirty when actions fail.

Fixes facebook#35295
- Modified resetFormInstance to check React fiber for controlled inputs
- Skips reset for inputs controlled by 'checked' or 'value' props
- Added tests for controlled and uncontrolled checkbox/radio behavior
- Fixes facebook#31695
- Add select element tests (controlled + uncontrolled)
- Add textarea tests (controlled + uncontrolled)
- Update tests to use outer container variable
- Fixes facebook#30580
@rdanciu11 rdanciu11 changed the title Fix: Controlled checkboxes and radio buttons reset on form submission Fix: Controlled form inputs reset after form submission, even though they should maintain their state. Dec 19, 2025
@rdanciu11 rdanciu11 changed the title Fix: Controlled form inputs reset after form submission, even though they should maintain their state. Fix: Controlled form inputs reset on form submission Dec 19, 2025
@rdanciu11
Copy link
Author

Update: I've confirmed the fix works for select elements and added tests

I've updated this PR to include tests for:

The fix works across all these input types because it checks React's internal fiber tree for control props (value or checked) rather than special-casing specific element types. I've also updated the PR title and description to reflect the biggerscope.

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

Projects

None yet

2 participants