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

ReactComponent.isValidComponent returns true for component classes #1164

Closed
sophiebits opened this issue Feb 24, 2014 · 5 comments · Fixed by #1394
Closed

ReactComponent.isValidComponent returns true for component classes #1164

sophiebits opened this issue Feb 24, 2014 · 5 comments · Fixed by #1394
Milestone

Comments

@sophiebits
Copy link
Collaborator

The last two assertions in this new test don't pass because of the duck-typing check added in fc2805f.

@sebmarkbage Not quite sure what you had in mind here. Not every object whose .type is a component class is a valid descriptor… right?

it('should identify valid components correctly', function() {
  var Component = React.createClass({
    render: function() {
      return <div />;
    }
  });

  expect(ReactComponent.isValidComponent(<div />)).toEqual(true);
  expect(ReactComponent.isValidComponent(<Component />)).toEqual(true);

  expect(ReactComponent.isValidComponent(null)).toEqual(false);
  expect(ReactComponent.isValidComponent(true)).toEqual(false);
  expect(ReactComponent.isValidComponent({})).toEqual(false);
  expect(ReactComponent.isValidComponent("string")).toEqual(false);
  expect(ReactComponent.isValidComponent(React.DOM.div)).toEqual(false);  // FAIL
  expect(ReactComponent.isValidComponent(Component)).toEqual(false);  // FAIL
});
@sebmarkbage
Copy link
Collaborator

This is an intermediate step. Currently the duck typing is flawed regardless. Descriptors will probably get an inheritance chain so that instanceof ReactDescriptor works as a safer check.

Only descriptors should pass. We could probably check for props too. It is expected that component classes themselves fail the test. Therefore it should also be renamed.

On Feb 24, 2014, at 7:42 AM, Ben Alpert notifications@github.com wrote:

The last two assertions in this new test don't pass because of the duck-typing check added in fc2805f.

@sebmarkbage Not quite sure what you had in mind here. Not every object whose .type is a component class is a valid descriptor… right?

it('should identify valid components correctly', function() {
var Component = React.createClass({
render: function() {
return

;
}
});

expect(ReactComponent.isValidComponent(

)).toEqual(true);
expect(ReactComponent.isValidComponent()).toEqual(true);

expect(ReactComponent.isValidComponent(null)).toEqual(false);
expect(ReactComponent.isValidComponent(true)).toEqual(false);
expect(ReactComponent.isValidComponent({})).toEqual(false);
expect(ReactComponent.isValidComponent("string")).toEqual(false);
expect(ReactComponent.isValidComponent(React.DOM.div)).toEqual(false); // FAIL
expect(ReactComponent.isValidComponent(Component)).toEqual(false); // FAIL
});

Reply to this email directly or view it on GitHub.

@sophiebits
Copy link
Collaborator Author

Right -- with the current code, isValidComponent returns true when passed a component class, which is wrong.

@sebmarkbage
Copy link
Collaborator

That's right. We should add that unit test.

Out of curiosity, how did you find this?

On Feb 24, 2014, at 1:51 PM, Ben Alpert notifications@github.com wrote:

Right -- with the current code, isValidComponent returns true when passed a component class, which is wrong.


Reply to this email directly or view it on GitHub.

@zpao zpao added this to the 0.9.1 milestone Feb 24, 2014
@sophiebits
Copy link
Collaborator Author

I was adding a warning for passing a component class to renderComponent because of this Stack Overflow question: http://stackoverflow.com/questions/21948048/react-cant-get-past-no-method-mountcomponentintonode.

@sebmarkbage
Copy link
Collaborator

I think this is fixed. Not sure if we have a solid unit test to cover this.

sophiebits added a commit to sophiebits/react that referenced this issue Apr 10, 2014
Fixes facebook#1164.

Test Plan: grunt test
chenglou added a commit that referenced this issue Apr 12, 2014
Add test for isValidDescriptor
valentyn90 pushed a commit to valentyn90/React-Router that referenced this issue Aug 27, 2021
Previously the checks for components were the same as class. This changes in the new version of react. See this issue: facebook/react#1164
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants