Skip to content

Bug: missing else statement in ReactDOMServerFormatConfig.js #22309

Closed as not planned
@justingrant

Description

@justingrant

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions