-
Notifications
You must be signed in to change notification settings - Fork 47.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reconciliation behaves differently with children-as-function and Consumer function #12715
Comments
I also wonder what should developers expect from function-as-child
|
This turned out to be more complicated than I thought. If we add some console logs we’ll indeed see that only the first span-creating function gets re-executed when the interval fires. This is why. In the first example, In the second example, Note that this is actually getting a bit more complicated than that in practice. In practice, React DevTools does highlight both of them if you remove the first empty text child:
This doesn’t mean React re-renders them both though. (You can verify by putting console logs.) What's happening here is that the top-level component that contains If we remove the text node, in your example tree, the closest node to the So when we don’t have a text node in the beginning, we end up highlighting the With the text node at the beginning, the tree looks like this: For the first row, again, we want to show that For the second row, we want to show that both Now the question is why do we count To sum up:
Thanks for reporting! |
https://jsfiddle.net/d4egov72/
In React Developer Tools, with Highlight updates:
What is the expected behavior?
The two divs should reconcile the same way, but the children-as-function variant does not update the DOM on setState() (which would be the ideal behavior since its return value does not change), while the consumer variant changes the DOM on every setState()
Note that the difference does not occur if:
The text was updated successfully, but these errors were encountered: