Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Merge cbd93b0 into 3cb22fa
Browse files Browse the repository at this point in the history
  • Loading branch information
edorivai committed Feb 1, 2018
2 parents 3cb22fa + cbd93b0 commit ee9a4ad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changelog.md
Expand Up @@ -2,6 +2,8 @@

### vNext

* Fix React Component detection bug in `getDataFromTree` [#1604](https://github.com/apollographql/react-apollo/pull/1604)

### 2.1.0-beta.0

* Beta release of all 2.1 features!
Expand Down
2 changes: 1 addition & 1 deletion src/getDataFromTree.ts
Expand Up @@ -59,7 +59,7 @@ export function walkTree<Cache>(

// Are we are a react class?
// https://github.com/facebook/react/blob/master/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js#L66
if (Component.prototype && Component.prototype.render) {
if (Component.prototype && (Component.prototype.render || Component.prototype.isReactComponent)) {
// typescript force casting since typescript doesn't have definitions for class
// methods
const _component = Component as any;
Expand Down
14 changes: 14 additions & 0 deletions test/server/getDataFromTree.test.tsx
Expand Up @@ -268,6 +268,20 @@ describe('SSR', () => {
);
expect(elementCount).toEqual(9);
});

it('basic classes with render on instance', () => {
let elementCount = 0;
class MyComponent extends (React.Component as any) {
render = () => {
return <div>{_.times(this.props.n, i => <span key={i} />)}</div>;
}
}
const MyCompAsAny = MyComponent as any;
walkTree(<MyCompAsAny n={5} />, {}, element => {
elementCount += 1;
});
expect(elementCount).toEqual(7);
});
});
});

Expand Down

0 comments on commit ee9a4ad

Please sign in to comment.