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

Commit

Permalink
Merge pull request #1604 from edorivai/patch-1
Browse files Browse the repository at this point in the history
Fix React Component detection
  • Loading branch information
leoasis authored Feb 1, 2018
2 parents 3cb22fa + cbd93b0 commit 4e7a87c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 4e7a87c

Please sign in to comment.