[react-dom] Honor disableInputAttributeSyncing for textarea defaultValue
Summary
The disableInputAttributeSyncing feature 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 the defaultValue attribute based on changes to the value prop 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 updateTextarea function in ReactDOMTextarea.js did not fully respect this flag. In certain scenarios, even when disableInputAttributeSyncing was true, React would still:
- Synchronize the
defaultValueattribute with thevalueprop ifvaluewas provided anddefaultValuewas not. - Set the
defaultValueattribute to an empty string if neithervaluenordefaultValueprops were provided.
This behavior was inconsistent with the intended purpose of the disableInputAttributeSyncing flag, potentially leading to unexpected defaultValue changes in applications relying on this flag for specific textarea integrations.
This change modifies updateTextarea to ensure that these updates to defaultValue only occur when disableInputAttributeSyncing is false (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:
- Modified
packages/react-dom-bindings/src/client/ReactDOMTextarea.js. - Added a new test case to
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.
-
- All existing tests in
ReactDOMTextarea-test.jsand the broader React test suite continue to pass with these changes.
- Modified
-
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 defaultValue might have been inadvertently changed by React despite the disableInputAttributeSyncing flag. The successful execution of all tests indicates that the fix behaves as expected and does not introduce regressions.
Hi @developerjhp!
Thank you for your pull request and welcome to our community.
Action Required
In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.
Process
In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.
Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.
If you have received this in error or have any questions, please contact us at [email protected]. Thanks!
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!
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.
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!