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
+87
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #30580. Ensures only uncontrolled , , 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 Added isControlledField() helper function - Detects if a form field is controlled by checking for React props (value or checked) Added resetFormFieldsAfterAction() function - Resets only uncontrolled fields while preserving controlled field state Updated requestFormReset() - Now uses the new controlled/uncontrolled detection logic Added dev logging - Console logs when controlled fields are skipped (development mode only) 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: Added isControlledField() helper function that detects if a form field is controlled (has value or checked props from React) 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 Modified requestFormReset() to use the new controlled/uncontrolled detection logic 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?