diff --git a/src/components/createConnect.js b/src/components/createConnect.js index 5a7b9de41..c3d152630 100644 --- a/src/components/createConnect.js +++ b/src/components/createConnect.js @@ -77,6 +77,8 @@ export default function createConnect(React) { } return function wrapWithConnect(WrappedComponent) { + let isStateless = !(WrappedComponent.prototype && WrappedComponent.prototype.isReactComponent) || !('prototype' in WrappedComponent); + class Connect extends Component { shouldComponentUpdate(nextProps, nextState) { @@ -199,6 +201,10 @@ export default function createConnect(React) { } render() { + if (isStateless) { + return ; + } + return ( diff --git a/test/components/connect.spec.js b/test/components/connect.spec.js index 25f6eb8a9..507280dea 100644 --- a/test/components/connect.spec.js +++ b/test/components/connect.spec.js @@ -1117,6 +1117,45 @@ describe('React', () => { expect(decorated.refs.wrappedInstance.someInstanceMethod()).toBe(someData); }); + it('should not add refs to wrapped instance if stateless', () => { + const store = createStore(() => ({})); + const decorator = connect(state => state); + const Decorated = decorator(() =>
); + + const tree = TestUtils.renderIntoDocument( + + + + ); + + const decorated = TestUtils.findRenderedComponentWithType(tree, Decorated); + expect(Object.keys(decorated.refs)).toExclude('wrappedInstance'); + }); + + it('should consider module pattern of non-Component-inheriting classes stateful', () => { + function MyComponent(initialProps) { + return { + state: { value: initialProps.initialValue }, + render: function render() { + return ; + } + }; + } + + const store = createStore(() => ({})); + const decorator = connect(state => state); + const Decorated = decorator(() => ); + + const tree = TestUtils.renderIntoDocument( + + + + ); + + const decorated = TestUtils.findRenderedComponentWithType(tree, Decorated); + expect(Object.keys(decorated.refs)).toInclude('wrappedInstance'); + }); + it('should wrap impure components without supressing updates', () => { const store = createStore(() => ({}));