isValidComponent returns false for component instances
In 0.11.0 React.isValidComponent() returns false when passed a component instance (not a descriptor).
Not sure if this is the intended behaviour but it seems counter intuitive. If it is intended, perhaps it could be mentioned in the docs.
Fiddle showing the behaviour in 0.11.0: http://jsfiddle.net/jsdf/j8TF9/1/ Fiddle showing previous behaviour in 0.10.0: http://jsfiddle.net/jsdf/M6pM5/1/
cc @sebmarkbage, this has come up a couple times now. Our terminology around component vs descriptor vs class has gotten more hazy.
I think we should work like this:
// would need to revert the current behavior
React.isValidComponent(React.renderComponent(Comp())) // true
React.isValidComponent(Comp()) // false
React.isValidComponent(Comp) // false
// would need to add this API
React.isValidDescriptor(React.renderComponent(Comp())) // false
React.isValidDescriptor(Comp()) // true
React.isValidDescriptor(Comp) // false
// should actually work like this already
React.isValidClass(React.renderComponent(Comp())) // false
React.isValidClass(Comp()) // false
React.isValidClass(Comp) // true
The direction we're heading there is actually no such thing as a component that can be statically verified. We have an internal discussion that I'll direct you to.
There are many different signatures that are valid components. It needs to be more precise such as instanceOf(ParticularComponent.type), certain categories like XHP or anything with a getDOMNode method.
On Jul 23, 2014, at 9:27 PM, Paul O’Shannessy [email protected] wrote:
cc @sebmarkbage, this has come up a couple times now. Our terminology around component vs descriptor vs class has gotten more hazy.
I think we should work like this:
// would need to revert the current behavior React.isValidComponent(React.renderComponent(Comp())) // true React.isValidComponent(Comp()) // false React.isValidComponent(Comp) // false
// would need to add this API React.isValidDescriptor(React.renderComponent(Comp())) // false React.isValidDescriptor(Comp()) // true React.isValidDescriptor(Comp) // false
// should actually work like this already React.isValidClass(React.renderComponent(Comp())) // false React.isValidClass(Comp()) // false React.isValidClass(Comp) // true — Reply to this email directly or view it on GitHub.
Can we warn and make the upgrade path very clear?
This just introduced a huge leak into our app because we were cleaning up React views inside Backbone legacy views by checking if the "view" is React.isValidComponent. My bad for not reading breaking changes properly—but it would be handy to have a way to validate an instance.
@sebmarkbage did we want anything to validate an actual instance? isValidComponent was a pretty good name that we used up. We don't really have a good way to see if some object is the return value of React.render vs something like a backbone view. It sounds like you don't really want anything, but let's decide.
isMounted is really the check the verifies if an instance is tied to the React system. We could make it static which is what I would prefer anyway: React.isMountedComponent(instance) That would allow you to differentiate which React version a component is mounted with, and that it is in fact a React component and not something else with isMounted on it. That seems like a good API.
A unmounted valid instance is just anything with a render function which seems like a useless test, and is also likely to change (new signatures). This makes it an unstable API. Failures might become passing in upgrades which seems bad. I'd like to hear the use case for those.