Skip to content
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

Merged
merged 1 commit into from
Jan 6, 2016
Merged

Trigger componentWillReceiveProps when context changes #5787

merged 1 commit into from
Jan 6, 2016

Conversation

milesj
Copy link
Contributor

@milesj milesj commented Jan 6, 2016

A quick fix that will trigger componentWillReceiveProps when either the props or context change. A fix for #5756.

var div = document.createElement('div');

ReactDOM.render(<Parent cntxt="foo">
<Parent.ChildWithoutContext>
Copy link
Contributor

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?

Copy link
Contributor Author

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)

@jimfb
Copy link
Contributor

jimfb commented Jan 6, 2016

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 componentWillReceiveProps upon context updates is the intended behavior, right? FTR, componentWillReceiveProps does accept context as a parameter.

@milesj
Copy link
Contributor Author

milesj commented Jan 6, 2016

Awesome to hear. I'll rebase the commits tomorrow.

@sophiebits
Copy link
Collaborator

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?

@milesj
Copy link
Contributor Author

milesj commented Jan 6, 2016

Agreed. I'm going to mess around with the tests a bit more and then rebase.

@facebook-github-bot
Copy link

@milesj updated the pull request.

@milesj
Copy link
Contributor Author

milesj commented Jan 6, 2016

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;
Copy link
Collaborator

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.

@sophiebits
Copy link
Collaborator

Looks good now – just a couple notes inline.

…when either props or context change. Fixes issue #5756
@milesj
Copy link
Contributor Author

milesj commented Jan 6, 2016

Done.

@facebook-github-bot
Copy link

@milesj updated the pull request.

@jimfb
Copy link
Contributor

jimfb commented Jan 6, 2016

Ok, looks good. Thanks @milesj!

jimfb added a commit that referenced this pull request Jan 6, 2016
Trigger componentWillReceiveProps when context changes
@jimfb jimfb merged commit 9b679ab into facebook:master Jan 6, 2016
@sophiebits
Copy link
Collaborator

Thanks!

@milesj
Copy link
Contributor Author

milesj commented Jan 6, 2016

Cheers, thanks guys.

@kayakyakr
Copy link

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.

@milesj milesj deleted the receive-props-context-fix branch March 2, 2016 20:25
@jimfb
Copy link
Contributor

jimfb commented Mar 2, 2016

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

@kayakyakr
Copy link

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.

@kayakyakr
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants