[react-dom] Honor disableInputAttributeSyncing for textarea defaultValue #33372
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.
Summary
The
disableInputAttributeSyncingfeature flag is intended to give developers more control over how React synchronizes certain attributes of input elements (like<textarea>) with their props after the initial render. Specifically for textareas, this flag should prevent React from automatically updating thedefaultValueattribute based on changes to thevalueprop or when no props are provided, once the component is mounted and potentially managed by user input or other non-React mechanisms.This pull request addresses an issue where the
updateTextareafunction inReactDOMTextarea.jsdid not fully respect this flag. In certain scenarios, even whendisableInputAttributeSyncingwastrue, React would still:defaultValueattribute with thevalueprop ifvaluewas provided anddefaultValuewas not.defaultValueattribute to an empty string if neithervaluenordefaultValueprops were provided.This behavior was inconsistent with the intended purpose of the
disableInputAttributeSyncingflag, potentially leading to unexpecteddefaultValuechanges in applications relying on this flag for specific textarea integrations.This change modifies
updateTextareato ensure that these updates todefaultValueonly occur whendisableInputAttributeSyncingisfalse(the default behavior), thus correctly honoring the flag and providing the expected control to developers.How did you test this change?
The changes were tested as follows:
Unit Tests:
packages/react-dom-bindings/src/client/ReactDOMTextarea.js.packages/react-dom/src/__tests__/ReactDOMTextarea-test.js:it('does not update defaultValue on input event', ...): This test specifically verifies that whendisableInputAttributeSyncingistrue, thedefaultValueattribute of a controlled textarea remains unchanged even when the textarea's live value is updated by aninputevent. This simulates user interaction and ensures that React does not incorrectly try to re-syncdefaultValueunder this flag.ReactDOMTextarea-test.jsand the broader React test suite continue to pass with these changes.Test Commands Executed:
yarn test packages/react-dom/src/__tests__/ReactDOMTextarea-test.js: Ran tests specifically for the modified test file. All tests passed.yarn test: Ran the entire test suite. All tests passed.yarn test --prod: Ran the test suite in the production environment. All tests passed.yarn lint: Checked for linting issues. No issues found.yarn prettier --check: Checked for formatting issues. No issues found. (Assumingyarn prettierwas run to format if needed).yarn flow: Ran Flow type checks. No issues found.The new test case directly addresses the scenario where
defaultValuemight have been inadvertently changed by React despite thedisableInputAttributeSyncingflag. The successful execution of all tests indicates that the fix behaves as expected and does not introduce regressions.