Skip to content

[Fiber] adds childContextTypes warnings for functional components #9043

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

Merged

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Feb 22, 2017

ReactStatelessComponent-test.js currently fails behind Fiber flags due to warnings not showing up when functional components mount or update when childContextTypes are defined on the functional component.

This PR ports the existing warning messages from stack and re-applies them to Fiber's functional components. Existing login within ReactFiberContext.js was also re-used on functional components (previously it was only used for class components) to fully full in line with the expected behaviour for the test assertions.

@gaearon gaearon changed the title adds childContextTypes warnings for functional components [Fiber] adds childContextTypes warnings for functional components Feb 22, 2017
@gaearon gaearon self-requested a review February 22, 2017 14:15
@trueadm trueadm requested a review from sophiebits February 22, 2017 14:17
@trueadm trueadm force-pushed the fix-fiber-functional-componment-childcontext branch from 5713667 to 9f75f35 Compare February 22, 2017 14:19
ReactStatelessComponent-test.js fails due to warnings not showing up when functional components mount or update. This PR ports the existing warnings from stack and re-applies them to fiber functional components and attempts to re-use some logic in ReactFiberContext that currently exists for showing warnings when dealing with class components.
@trueadm trueadm force-pushed the fix-fiber-functional-componment-childcontext branch from 9f75f35 to a9325e2 Compare February 22, 2017 14:21
Component.displayName || Component.name || 'Component'
);
if (Component.childContextTypes) {
warnAboutMissingGetChildContext(workInProgress);
Copy link
Collaborator

@sebmarkbage sebmarkbage Feb 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test is wrong. It doesn't make sense to both warn for childContextTypes being defined and also warn for that you should provide a getChildContext which you cannot do. It's not actionable.

IMO we should either fix this in Stack and remove it or gate the test on ReactDOMFeatureFlags.useFiber and change the assertion for the Fiber case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, completely. I was unsure if we wanted 1:1 parity with Stack in regards to these strange warning messages. I don't know why anyone would ever need the second warning message when using functional components, given they can't ever use getChildContext on the components. Was there intentions at some point to allow functional components to use getChildContext?

@trueadm
Copy link
Contributor Author

trueadm commented Feb 23, 2017

@sebmarkbage I've updated the PR to reflect those changes. I opted to instead add a flag in the test for Fiber rather than changing the warning messages on Stack.

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepting with a small nit above below.

'childContextTypes from it.'
);
// Stack and Fiber differ in terms of they show warnings
if (!ReactDOMFeatureFlags.useFiber) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's flip this to be a positive condition, it's easy to misread.

@trueadm trueadm merged commit 23f2451 into facebook:master Feb 23, 2017
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.

4 participants