diff --git a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js index 6ac4ab1796b8a..61a48f219685f 100644 --- a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js +++ b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js @@ -1107,7 +1107,9 @@ var ReactCompositeComponent = { if (__DEV__) { var componentName = component && component.getName ? component.getName() : 'a component'; - warning(publicComponentInstance != null, + warning( + publicComponentInstance != null || + component._compositeType !== CompositeTypes.StatelessFunctional, 'Stateless function components cannot be given refs ' + '(See ref "%s" in %s created by %s). ' + 'Attempts to access this ref will fail.', diff --git a/src/renderers/testing/__tests__/ReactTestRenderer-test.js b/src/renderers/testing/__tests__/ReactTestRenderer-test.js index e562867fd2dbb..95f7f9f4d948d 100644 --- a/src/renderers/testing/__tests__/ReactTestRenderer-test.js +++ b/src/renderers/testing/__tests__/ReactTestRenderer-test.js @@ -206,6 +206,31 @@ describe('ReactTestRenderer', function() { expect(log).toEqual([null]); }); + it('warns correctly for refs on SFCs', function() { + spyOn(console, 'error'); + function Bar() { + return