Bug: child.type no longer maintains function equality
See original GitHub issueDo you want to request a feature or report a bug?
Bug
What is the current behavior?
When I map over props.children
to figure out whether or not a child is of a particular type, the function reference is no longer the same.
This is a regression between 16.9.0 and 16.10.0, and it shows up at least when using Gatsby. It does not, however, show up on the client side. Perhaps it has something to do with the server renderer?
Here’s a reproduction of the code leading to the bug:
Demo where it’s working in 16.9.0 Demo where it’s not working anymore in 16.10.0
What is the expected behavior?
I’d expect the following to work the same in 16.9.x and 16.10.x
function Menu(props) { return <div className="menu">{props.children}</div>; }
function MenuItem(props) {
const hasSubMenu = React.Children.toArray(props.children).some(
child => child.type === Menu // ⬅this check no longer works
);
// do some logic with hasSubMenu
return props.children;
}
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Broken in 16.10.0 and 16.10.1 - works in 16.9.0 at least - haven’t tried with lower versions.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
@selbekk it sounds like this might be Gatsby specific, so I recommend following up with them. If you can provide a reproduction that shows a regression in React itself I’m happy to re-open!
Alright - I’ll see what I can do. Agree that it might be Gatsby-specific somehow