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

skip null ref warning for ReactTestRenderer #7658

Merged

Conversation

aweary
Copy link
Contributor

@aweary aweary commented Sep 5, 2016

Resolves #7645 as far as the warning goes--assuming that toJSON isn't going to be implemented in other renderers.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 87.192% when pulling b89824f on Aweary:fix-react-test-renderer-ref-warning into 6a525fd on facebook:master.

@@ -1107,7 +1107,7 @@ var ReactCompositeComponent = {
if (__DEV__) {
var componentName = component && component.getName ?
component.getName() : 'a component';
warning(publicComponentInstance != null,
Copy link
Collaborator

@gaearon gaearon Sep 5, 2016

Choose a reason for hiding this comment

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

Can we check this._compositeType instead, and only warn for stateless functional components? It seems like this would solve the issue by making the warning more specific without hardcoding information about test renderer. Another upside is that the warning would still fire if you try to use refs with stateless components incorrectly while using test renderer for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oooo, I didn't know about _compositeType, thanks! 🎉

@coveralls
Copy link

Coverage Status

Coverage remained the same at 87.192% when pulling 11315dc on Aweary:fix-react-test-renderer-ref-warning into 6a525fd on facebook:master.

@gaearon gaearon added this to the 15-next milestone Sep 6, 2016
@gaearon gaearon assigned gaearon and unassigned sophiebits Sep 6, 2016
@gaearon gaearon merged commit 06ea71d into facebook:master Sep 6, 2016
@gaearon
Copy link
Collaborator

gaearon commented Sep 6, 2016

Looks great. Thanks.

warning(publicComponentInstance != null,
warning(
publicComponentInstance != null ||
component._compositeType !== CompositeTypes.StatelessFunctional,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note: this is a little sketchy because component might not be a ReactCompositeComponent (and thus wouldn't have _compositeType), but I suppose it is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should still suppress the warning correctly though, right? Since it wouldn't be a SFC if there wasn't a _compositeType anyways. I can add an additional check to make it safer if you'd like

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, it would. I avoid polymorphic accesses like this whenever possible because they're slower but I'm not sure there's a better option here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree, sorry I missed this. Should we add a check for typeof component._currentElement.type === 'function'?

Copy link
Collaborator

Choose a reason for hiding this comment

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

component._currentElement is still polymorphic. We'd probably need to pass the component type along with the component instance if we wanted to avoid this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is fine as-is, just wanted to note it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I understand this now. Different hidden class? Seems like we do this in many places anyway but thanks for explaining.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah.

@zpao zpao modified the milestones: 15.3.2, 15-next Sep 8, 2016
acdlite pushed a commit to acdlite/react that referenced this pull request Sep 9, 2016
zpao pushed a commit that referenced this pull request Sep 15, 2016
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.

6 participants