react icon indicating copy to clipboard operation
react copied to clipboard

Parent-based context fails if component updates its child

Open agundermann opened this issue 11 years ago • 3 comments

It seems that if a component implementing getChildContext is updated to render a different (top-level) child, react doesn't call getChildContext on that updated component (for parent-based context). So the new child will effectively get the context of its grandparent instead (if there is one).

While this doesn't seem to break anything (I assume that is because react still prioritizes owner-based context which works fine), it leads to a "contexts differ" warning.

Here's a fiddle: http://jsfiddle.net/2fd0jvo5/10/

Once you click "Show Foo", you should see a warning in the console. When wrapping the render output with a static element such as <span>, the warning will not appear.

I'm not very familiar with the source code, but for what it's worth, the warning goes away if I replace this line with this._processChildContext(context).

agundermann avatar Mar 13 '15 15:03 agundermann

cc @jsfb - sounds like we'll definitely want to address this before we cut over.

zpao avatar Mar 13 '15 20:03 zpao

@taurose: I have submitted the PR #3494 following your suggestion (test-case included). You can close the issue.

letiemble avatar Mar 25 '15 20:03 letiemble

:+1:

agundermann avatar Mar 25 '15 20:03 agundermann