Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions packages/react-dom-bindings/src/client/ReactDOMTextarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import isArray from 'shared/isArray';

import {getCurrentFiberOwnerNameInDevOrNull} from 'react-reconciler/src/ReactCurrentFiber';
import {getToStringValue, toString} from './ToStringValue';
import {disableTextareaChildren} from 'shared/ReactFeatureFlags';
import {disableTextareaChildren, disableInputAttributeSyncing} from 'shared/ReactFeatureFlags';

import {track, trackHydrated} from './inputValueTracking';
import {queueChangeEvent} from '../events/ReactDOMEventReplaying';
Expand Down Expand Up @@ -75,18 +75,21 @@ export function updateTextarea(
if (newValue !== node.value) {
node.value = newValue;
}
// TOOO: This should respect disableInputAttributeSyncing flag.
if (defaultValue == null) {
if (node.defaultValue !== newValue) {
node.defaultValue = newValue;
if (!disableInputAttributeSyncing) {
if (defaultValue == null) {
if (node.defaultValue !== newValue) {
node.defaultValue = newValue;
}
return;
}
return;
}
}
if (defaultValue != null) {
node.defaultValue = toString(getToStringValue(defaultValue));
} else {
node.defaultValue = '';
if (!disableInputAttributeSyncing) {
node.defaultValue = '';
}
}
}

Expand Down
30 changes: 30 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMTextarea-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,36 @@ describe('ReactDOMTextarea', () => {
}
});

it('does not update defaultValue on input event', async () => {
const setUntrackedValue = Object.getOwnPropertyDescriptor(
HTMLTextAreaElement.prototype,
'value',
).set;

const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
document.body.appendChild(container);

try {
const node = await renderTextarea(
<textarea value="foo" onChange={emptyFunction} />,
container,
root,
);

setUntrackedValue.call(node, 'bar');
node.dispatchEvent(
new Event('input', {bubbles: true, cancelable: false}),
);

if (ReactFeatureFlags.disableInputAttributeSyncing) {
expect(node.defaultValue).toBe('foo');
}
} finally {
document.body.removeChild(container);
}
});

if (ReactFeatureFlags.disableTextareaChildren) {
it('should ignore children content', async () => {
const container = document.createElement('div');
Expand Down