question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: child.type no longer maintains function equality

See original GitHub issue

Do 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
awearycommented, Oct 21, 2019

@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!

0reactions
selbekkcommented, Oct 21, 2019

Alright - I’ll see what I can do. Agree that it might be Gatsby-specific somehow

Read more comments on GitHub >

github_iconTop Results From Across the Web

Protecting Students With Disabilities - Department of Education
Frequently Asked Questions about Section 504 requirements for the education by school districts of students with disabilities.
Read more >
Documentation - TypeScript 3.7
In this example if someValue isn't equal to 42 , then assert will throw an AssertionError . Assertions in JavaScript are often used...
Read more >
COMMON ERRORS IN KRONOS AND HOW TO FIX THEM
TIP: Do a CTRL + Click on the topic to link to the error details ... Some employees think it is okay to...
Read more >
unittest — Unit testing framework — Python 3.11.1 ...
Registers a type-specific method called by assertEqual() to check if two objects of exactly the same typeobj (not subclasses) compare equal. function must...
Read more >
Inheritance and the prototype chain - JavaScript | MDN
In JavaScript, any function can be added to an object in the form of a property.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found