Skip to content

Conversation

@developerjhp
Copy link

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.

…ltValue

The updateTextarea function in ReactDOMTextarea.js previously did not
fully respect the disableInputAttributeSyncing flag when determining
whether to update the textarea's defaultValue attribute.

This change ensures that:
- If disableInputAttributeSyncing is true, the defaultValue attribute
  is not automatically synchronized with the value prop, nor is it
  set to an empty string if no value or defaultValue props are provided.
- If disableInputAttributeSyncing is false (the default), the existing
  behavior of synchronizing defaultValue is maintained.

This aligns the textarea component's behavior with the intended purpose
of the disableInputAttributeSyncing flag.
Adds a test case to ensure that the `defaultValue` attribute of a
controlled textarea is not modified by React in response to an `input`
event when the `disableInputAttributeSyncing` feature flag is enabled.

Even if the live value of the textarea changes due to user input,
the `defaultValue` attribute (which reflects the initial value or the
value from props when it was last set) should remain unchanged under
this flag.
@facebook-github-bot
Copy link
Contributor

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 cla@meta.com. Thanks!

@facebook-github-bot
Copy link
Contributor

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

@developerjhp developerjhp changed the title fix(react-dom): Honor disableInputAttributeSyncing for textarea defaultValue [react-dom] Honor disableInputAttributeSyncing for textarea defaultValue May 31, 2025
@github-actions
Copy link

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 Aug 29, 2025
@github-actions
Copy link

github-actions bot commented Sep 5, 2025

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 Sep 5, 2025
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.

2 participants