-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Trigger componentWillReceiveProps when context changes #5787
Conversation
var div = document.createElement('div'); | ||
|
||
ReactDOM.render(<Parent cntxt="foo"> | ||
<Parent.ChildWithoutContext> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little weird. Why are you using Parent.ChildWithoutContext
instead of ChildWithoutContext
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to recreate the scenario in my codebase where componentWillReceiveProps
wasn't firing, as seen here: #5756 (comment)
Looks good to me. We will probably want to squash before merging. I'll tentatively accept, but will leave it open for a day or two to collect any additional feedback before merging. @sebmarkbage @spicyj Calling |
Awesome to hear. I'll rebase the commits tomorrow. |
Yeah, this change makes sense though the test case looks very complicated. I am not even sure it is testing the right thing – aren't the props changing since you recreate the element each time? |
Agreed. I'm going to mess around with the tests a bit more and then rebase. |
@milesj updated the pull request. |
Ok, I reworked the test case a bit so that it's apparent that context has changed and props haven't. Also rebased into 1 commit. |
}, | ||
}); | ||
|
||
Parent.ChildWithContext = ChildWithContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove these and just reference the components directly? Shouldn't make any practical difference but it's a bit simpler.
Looks good now – just a couple notes inline. |
…when either props or context change. Fixes issue #5756
Done. |
@milesj updated the pull request. |
Ok, looks good. Thanks @milesj! |
Trigger componentWillReceiveProps when context changes
Thanks! |
Cheers, thanks guys. |
Would it be possible to merge this change into 0.14-stable for 0.14.8? It's blocking and, as much as I love living on the bleeding edge, running 0.15.alpha in production makes me nervous. |
@kayakyakr If it makes you feel any better, the first release candidate of v15 will be released within the next two days. Also, Facebook is already running React v15 in production now. Honestly, I don't think a 0.14.8 is likely, but @zpao keeps telling me that he is open to doing another point release, so what do I know? If you're blocked and don't want to jump to v15, you could always checkout 0.14-stable and cherry-pick this commit over, build yourself, and use that - which is basically what we would do for a 0.14.8 release anyway. I know it's not a perfect solution, but maybe one of those ideas will help. |
Ah, if an RC is scheduled for the next few days, then that's awesome, please disregard. I'm OK with developing against 0.15.alpha.1, no problem. |
I found an interaction bug with react-router: route changes no longer trigger componentWillReceiveProps after this change. I'm still investigating if it's an issue that can be solved in react-router or if it will require a change to the way this is done. |
A quick fix that will trigger
componentWillReceiveProps
when either the props or context change. A fix for #5756.