Skip to content

Fix: Prevent reset of controlled form fields after form actionFix: Prevent reset of controlled form fields after form actionfeat: Add controlled field detection for form reset functionalityAdd … - #34295

Closed
DHANUSHRAJA22 wants to merge 1 commit into
react:mainfrom
DHANUSHRAJA22:patch-1

Conversation

@DHANUSHRAJA22

@DHANUSHRAJA22 DHANUSHRAJA22 commented Aug 25, 2025 •

Copy link
Copy Markdown

Fixes #30580. Ensures only uncontrolled <input>, <select>, and <textarea> fields are reset after form action. Controlled fields (with value or checked props) are skipped. Includes helper and dev logging.

Summary

This PR addresses issue #30580 by implementing controlled field detection in form reset functionality. The current implementation was resetting all form fields after a form action, which was causing controlled React components to lose their managed state.

What changed

  1. Added isControlledField() helper function - Detects if a form field is controlled by checking for React props (value or checked)
  2. Added resetFormFieldsAfterAction() function - Resets only uncontrolled fields while preserving controlled field state
  3. Updated requestFormReset() - Now uses the new controlled/uncontrolled detection logic
  4. Added dev logging - Console logs when controlled fields are skipped (development mode only)
  5. Exported helper functions - Available for potential external use

How it works

The solution examines each form element's React fiber node to determine if it has controlled props:

  • For <input> elements: checks for value prop (text inputs) or checked prop (checkboxes/radio)
  • For <textarea> and <select> elements: checks for value prop
  • Controlled fields are skipped during reset, preserving React's state management
  • Uncontrolled fields are reset as before

Testing

Tested with forms containing both controlled and uncontrolled components. Verified that:

  • Controlled fields maintain their React-managed state after form actions
  • Uncontrolled fields are properly reset to default values
  • Dev logging correctly identifies controlled fields…controlled field detection for form reset functionalityAdd controlled field detection for form reset functionalityUpdate ReactDOMFormActions.js

This commit enhances the form reset functionality in ReactDOMFormActions.js by:

  1. Added isControlledField() helper function that detects if a form field is controlled (has value or checked props from React)
  2. Added resetFormFieldsAfterAction() function that resets form fields after successful form action with logic to:
    • Skip resetting controlled fields (preserving React state management)
    • Reset uncontrolled fields as before
  3. Modified requestFormReset() to use the new controlled/uncontrolled detection logic
  4. Exported helper functions for potential external use

This ensures that controlled components maintain their state while uncontrolled components are properly reset after form actions.

Summary

How did you test this change?

…controlled field detection for form reset functionalityAdd controlled field detection for form reset functionalityUpdate ReactDOMFormActions.js

This commit enhances the form reset functionality in ReactDOMFormActions.js by:

1. Added isControlledField() helper function that detects if a form field is controlled (has value or checked props from React)
2. Added resetFormFieldsAfterAction() function that resets form fields after successful form action with logic to:
   - Skip resetting controlled fields (preserving React state management)
   - Reset uncontrolled fields as before
3. Modified requestFormReset() to use the new controlled/uncontrolled detection logic
4. Exported helper functions for potential external use

This ensures that controlled components maintain their state while uncontrolled components are properly reset after form actions.
@meta-cla meta-cla Bot added the CLA Signed label Aug 25, 2025
@DrWellsy

Copy link
Copy Markdown

I tested this change with forms that mix controlled and uncontrolled fields

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.

@github-actions github-actions Bot added the Resolution: Stale Automatically closed due to inactivity label Feb 16, 2026
@github-actions

Copy link
Copy Markdown

Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you!

@github-actions github-actions Bot closed this Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Resolution: Stale Automatically closed due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants