Skip to content

Commit

Permalink
Don't update textarea defaultValue unnecessarily
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Apr 10, 2023
1 parent e5146cb commit 00572cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/react-dom-bindings/src/client/ReactDOMTextarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ export function validateTextareaProps(element: Element, props: Object) {
export function updateTextarea(element: Element, props: Object) {
const node: HTMLTextAreaElement = (element: any);
const value = getToStringValue(props.value);
const defaultValue = getToStringValue(props.defaultValue);
if (defaultValue != null) {
node.defaultValue = toString(defaultValue);
} else {
node.defaultValue = '';
}
if (value != null) {
// Cast `value` to a string to ensure the value is set correctly. While
// browsers typically do this as necessary, jsdom doesn't.
Expand All @@ -76,10 +70,19 @@ export function updateTextarea(element: Element, props: Object) {
node.value = newValue;
}
// TOOO: This should respect disableInputAttributeSyncing flag.
if (props.defaultValue == null && node.defaultValue !== newValue) {
node.defaultValue = newValue;
if (props.defaultValue == null) {
if (node.defaultValue !== newValue) {
node.defaultValue = newValue;
}
return;
}
}
const defaultValue = getToStringValue(props.defaultValue);
if (defaultValue != null) {
node.defaultValue = toString(defaultValue);
} else {
node.defaultValue = '';
}
}

export function initTextarea(element: Element, props: Object) {
Expand Down
1 change: 1 addition & 0 deletions packages/react-dom/src/__tests__/ReactDOMTextarea-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ describe('ReactDOMTextarea', () => {
ref={n => (node = n)}
value="foo"
onChange={emptyFunction}
data-count={this.state.count}
/>
</div>
);
Expand Down

0 comments on commit 00572cc

Please sign in to comment.