react icon indicating copy to clipboard operation
react copied to clipboard

[react-dom] Honor disableInputAttributeSyncing for textarea defaultValue

Open developerjhp opened this issue 7 months ago • 2 comments

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:

  1. Synchronize the defaultValue attribute with the value prop if value was provided and defaultValue was not.
  2. Set the defaultValue attribute to an empty string if neither value nor defaultValue props 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:

  1. 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 when disableInputAttributeSyncing is true, the defaultValue attribute of a controlled textarea remains unchanged even when the textarea's live value is updated by an input event. This simulates user interaction and ensures that React does not incorrectly try to re-sync defaultValue under this flag.
    • All existing tests in ReactDOMTextarea-test.js and the broader React test suite continue to pass with these changes.
  2. 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. (Assuming yarn prettier was 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.

developerjhp avatar May 29 '25 08:05 developerjhp

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!

facebook-github-bot avatar May 29 '25 08:05 facebook-github-bot

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

facebook-github-bot avatar May 29 '25 09:05 facebook-github-bot

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[bot] avatar Aug 29 '25 11:08 github-actions[bot]

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[bot] avatar Sep 05 '25 12:09 github-actions[bot]