I found this bug while working on an unrelated PR #22064. Looks like there's a missing else, because the value set in line 978 is always overwritten in line 980. Given that children.toString() and children[0].toString() will return the same string for one-element arrays, I assume the best (for perf and bundle size) fix would be to remove the assignment inside the if block.
|
if (isArray(children)) { |
|
invariant( |
|
children.length <= 1, |
|
'<textarea> can only have at most one child.', |
|
); |
|
value = '' + children[0]; |
|
} |
|
value = '' + children; |
Because the observable behavior is identical whether or not children is a scalar or a one-element array, I'm not sure a test could be written to verify a fix.
EDIT: I updated the text above after I learned that Array.prototype.toString() acts the same as Array.prototype.join(). JavaScript teaches me something new every day!
I found this bug while working on an unrelated PR #22064. Looks like there's a missing
else, because thevalueset in line 978 is always overwritten in line 980. Given thatchildren.toString()andchildren[0].toString()will return the same string for one-element arrays, I assume the best (for perf and bundle size) fix would be to remove the assignment inside theifblock.react/packages/react-dom/src/server/ReactDOMServerFormatConfig.js
Lines 973 to 980 in fd5e01c
Because the observable behavior is identical whether or not
childrenis a scalar or a one-element array, I'm not sure a test could be written to verify a fix.EDIT: I updated the text above after I learned that
Array.prototype.toString()acts the same asArray.prototype.join(). JavaScript teaches me something new every day!