react: Bug: missing `else` statement in ReactDOMServerFormatConfig.js

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.

https://github.com/facebook/react/blob/fd5e01c2e0dbbeaff954d13fc6bc11bfc65e7dcf/packages/react-dom/src/server/ReactDOMServerFormatConfig.js#L973-L980

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!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (6 by maintainers)

Commits related to this issue

Most upvoted comments

This issue hasn’t been assigned to anyone so I think anyone is free to open PR for it @amensum