-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
check if type.prototype is object in instantiateReactComponent #3638
Conversation
@@ -40,6 +40,7 @@ assign( | |||
function isInternalComponentType(type) { | |||
return ( | |||
typeof type === 'function' && | |||
typeof type.prototype === 'object' && |
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'm a little curious how this would interact with ES6 classes if we upgrade to ES6. Is the prototype of an ES6 class a object or a function? I feel like what you are actually wanting to check is if the prototype is undefined in order to avoid throwing on the next line.
Looks good. I suggest changing it to check for undefined instead of checking for object, since that's what you're really trying to protect against. Also, let's add a unit test that simulates the failure case you were experiencing and asserts that we now return false. |
Looks good to me. Clearly Sebastian agrees. @teosz I'd still like to see a unit test that verifies this functionality (ie. simulates the case you were running into, so we don't ever accidentally break that for you). But I suppose that can be a separate PR. |
check if type.prototype is object in instantiateReactComponent
@@ -40,6 +40,7 @@ assign( | |||
function isInternalComponentType(type) { | |||
return ( | |||
typeof type === 'function' && | |||
typeof type.prototype !== 'undefined' && |
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.
you could just do
type.prototype !== undefined
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.
True. I don't have a particular preference.
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.
for consistency i verified type like others lines
check if type.prototype is object in instantiateReactComponent
check if type.prototype is object in instantiateReactComponent
check if type.prototype is object in instantiateReactComponent
When I try instantiate a component inside react router nested view I get :
Uncaught TypeError: Cannot read property 'mountComponent' of undefined