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

Conversation

Projects
None yet
5 participants
@milesj
Copy link
Contributor

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>

This comment has been minimized.

Copy link
@jimfb

jimfb Jan 6, 2016

Contributor

This is a little weird. Why are you using Parent.ChildWithoutContext instead of ChildWithoutContext?

This comment has been minimized.

Copy link
@milesj

milesj Jan 6, 2016

Author Contributor

I was trying to recreate the scenario in my codebase where componentWillReceiveProps wasn't firing, as seen here: #5756 (comment)

@jimfb

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor Author

commented Jan 6, 2016

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

@sophiebits

This comment has been minimized.

Copy link
Collaborator

commented Jan 6, 2016

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

This comment has been minimized.

Copy link
Contributor Author

commented Jan 6, 2016

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

@facebook-github-bot

This comment has been minimized.

Copy link

commented Jan 6, 2016

@milesj updated the pull request.

@milesj milesj force-pushed the milesj:receive-props-context-fix branch from 193b43a to 0177e4c Jan 6, 2016

@milesj

This comment has been minimized.

Copy link
Contributor Author

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;

This comment has been minimized.

Copy link
@sophiebits

sophiebits Jan 6, 2016

Collaborator

Can you remove these and just reference the components directly? Shouldn't make any practical difference but it's a bit simpler.


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

ReactDOM.render(<Parent>

This comment has been minimized.

Copy link
@sophiebits

sophiebits Jan 6, 2016

Collaborator

nit: to match our usual style, can you add a linebreak after ( and indent the next line two spaces? similarly, it should end

  </Parent>,
  div
);
@sophiebits

This comment has been minimized.

Copy link
Collaborator

commented Jan 6, 2016

Looks good now – just a couple notes inline.

Updated ReactCompositeComponent to trigger componentWillReceiveProps …
…when either props or context change. Fixes issue #5756

@milesj milesj force-pushed the milesj:receive-props-context-fix branch from 0177e4c to f4c5b2c Jan 6, 2016

@milesj

This comment has been minimized.

Copy link
Contributor Author

commented Jan 6, 2016

Done.

@facebook-github-bot

This comment has been minimized.

Copy link

commented Jan 6, 2016

@milesj updated the pull request.

@jimfb

This comment has been minimized.

Copy link
Contributor

commented Jan 6, 2016

Ok, looks good. Thanks @milesj!

jimfb added a commit that referenced this pull request Jan 6, 2016

Merge pull request #5787 from milesj/receive-props-context-fix
Trigger componentWillReceiveProps when context changes

@jimfb jimfb merged commit 9b679ab into facebook:master Jan 6, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@sophiebits

This comment has been minimized.

Copy link
Collaborator

commented Jan 6, 2016

Thanks!

@milesj

This comment has been minimized.

Copy link
Contributor Author

commented Jan 6, 2016

Cheers, thanks guys.

@kayakyakr

This comment has been minimized.

Copy link

commented Mar 2, 2016

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 milesj:receive-props-context-fix branch Mar 2, 2016

@jimfb

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link

commented Mar 2, 2016

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

This comment has been minimized.

Copy link

commented Mar 3, 2016

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
You can’t perform that action at this time.