Skip to content

Commit e915eee

Browse files
committed
Fix textarea bug
The test changes revealed a bug with textarea. It happens because we currently always insert trailing comment nodes. We should optimize that away. However, we also don't really support complex children so we should toString it anyway which is what partial renderer used to do.
1 parent f62de1d commit e915eee

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/react-dom/src/__tests__/ReactDOMServerIntegrationTextarea-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ describe('ReactDOMServerIntegrationTextarea', () => {
4949
expect(e.value).toBe('foo');
5050
});
5151

52+
itRenders('a textarea with a value of undefined', async render => {
53+
const e = await render(<textarea value={undefined} />);
54+
expect(e.getAttribute('value')).toBe(null);
55+
expect(e.value).toBe('');
56+
});
57+
5258
itRenders('a textarea with a value and readOnly', async render => {
5359
const e = await render(<textarea value="foo" readOnly={true} />);
5460
// textarea DOM elements don't have a value **attribute**, the text is

packages/react-dom/src/server/ReactDOMServerFormatConfig.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,17 @@ function pushStartTextArea(
10011001
target.push(leadingNewline);
10021002
}
10031003

1004-
return value;
1004+
// ToString and push directly instead of recurse over children.
1005+
// We don't really support complex children in the value anyway.
1006+
// This also currently avoids a trailing comment node which breaks textarea.
1007+
if (value !== null) {
1008+
if (__DEV__) {
1009+
checkAttributeStringCoercion(value, 'value');
1010+
}
1011+
target.push(stringToChunk(encodeHTMLTextNode('' + value)));
1012+
}
1013+
1014+
return null;
10051015
}
10061016

10071017
function pushSelfClosing(

0 commit comments

Comments
 (0)