-
Notifications
You must be signed in to change notification settings - Fork 47k
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
skip null ref warning for ReactTestRenderer #7658
Conversation
@@ -1107,7 +1107,7 @@ var ReactCompositeComponent = { | |||
if (__DEV__) { | |||
var componentName = component && component.getName ? | |||
component.getName() : 'a component'; | |||
warning(publicComponentInstance != null, |
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 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.
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.
Oooo, I didn't know about _compositeType
, thanks! 🎉
b89824f
to
11315dc
Compare
Looks great. Thanks. |
warning(publicComponentInstance != null, | ||
warning( | ||
publicComponentInstance != null || | ||
component._compositeType !== CompositeTypes.StatelessFunctional, |
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.
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.
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.
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
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.
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.
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.
Agree, sorry I missed this. Should we add a check for typeof component._currentElement.type === 'function'
?
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.
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.
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 think this is fine as-is, just wanted to note it.
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.
Oh, I understand this now. Different hidden class? Seems like we do this in many places anyway but thanks for explaining.
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.
Yeah.
(cherry picked from commit 06ea71d)
Resolves #7645 as far as the warning goes--assuming that
toJSON
isn't going to be implemented in other renderers.