-
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
Unnecessary re-rendering under bailed-out components when a legacy context provider and a deep child are updated in the same batch #11508
Comments
You're leaving me in suspense 😀 |
I am having the same problem: children get updated while container's shouldComponentUpdate return false. Didn't happened in version15. |
@gespiton Unfortunately this is not helpful without a reproducing example. |
This code looks very odd: constructor(props) {
super(props);
this.state = props;
} Why are you doing this? |
oh.... I've some misunderstanding with props and state, I'll change them later, but is this the problem? maybe I should make a simplified repo? |
Yes, further simplifying would be great! |
I’m going to close this. We’re 90% certain we’ve tracked down the issue to
There still appears to be a subtle difference between React 15 and 16 with React Broadcast’s sCU skipping, but I have been utterly unable to make a minimal repro and it’s only appeared in one very small edge case of our products so 🤷♂️ |
@iamdustan Did you find a solution to your problem? @gaearon I made a simple reproduction of the issue here https://github.com/johanobergman/react-context-render-bug/blob/master/src/index.js. It seems like updates from a top level container that are blocked by an intermediate Seems really wierd but I started noticing this when I made my |
Can you turn this into a failing unit test for the React repo? |
I could try. I've further narrowed it down and it seems like it happens when a child and parent component are updated within the same tick, and the parent defines |
I've added a failing test in my repo: https://github.com/johanobergman/react-context-render-bug/blob/master/src/index.test.js, but I'm not sure where I'd put it in the React repo. Would you mind having a look? |
You can search for files ending with |
Here's a hosted version of the repro using the latest release (16.4.1). You can see that the issue is still occurring. |
Yeah this seems to be a regression introduced in 16.0. |
Did you end up working around this somehow? |
I stumbled into this one also. It almost broke me! |
I looked into fixing this but it's pretty convoluted and didn't feel like it's worth going down the rabbit hole. We intend to make it easier to upgrade to new context, and after that we should deprecate the legacy one. |
Makes sense @gaearon. I am just relieved that I found this was an actual issue and that I was not going insane. |
@alexreardon You can work around this behaviour by wrapping some of your |
I just wasted a bunch of time tracking this down as well. It's worth noting: |
For completeness, I've bisected to commit 764531d as the one which has introduced this regression. It looks like a change that cannot be simply reverted. |
Yeah that’s when we switched over to the new implementation of React. The bug has likely been there since the beginning. As far as I’m aware there is no easy fix for this, and using the legacy context in general is discouraged. It’s already deprecated in the Strict Mode, for example. Now that we have an easier way to access the official Context API from both classes (via Feel free to continue the discussion though. |
This issue is going to start off mostly theoretical as I’m still working to make a minimal repro case.
We have a scenario where one component is having
shouldComponentUpdate()
return false to bail out, but a child component is still having itsrender
method called.Avoiding many details this is roughly what we have:
While this case does work as expected it seems to be in the direction of the
errors we’re seeing.
There is something taking place in our render cycle where B is being rendered
without reusing the
item
prop from the previous reconcile.My first question is are there any theories on why this may be happening that I
can explore? We are using
context
as the parent ofA
and asB
and theseare reading from a
flux
-thing (I think a fork of the original OSS Flux), theythey these are both passing all props through and not having any naming
collisions. I’m fairly certain we are not performing any mutations on our end.
(If I do manage to pull off a repro case I will immediately post it here with
utter joy in my heart)
cc @acdlite @gaearon (this is the issue I was asking about in Messenger recently)
The text was updated successfully, but these errors were encountered: