diff --git a/src/renderers/shared/reconciler/ReactCompositeComponent.js b/src/renderers/shared/reconciler/ReactCompositeComponent.js
index b96ece5133..c4729e39ea 100644
--- a/src/renderers/shared/reconciler/ReactCompositeComponent.js
+++ b/src/renderers/shared/reconciler/ReactCompositeComponent.js
@@ -808,8 +808,10 @@ var ReactCompositeComponentMixin = {
attachRef: function(ref, component) {
var inst = this.getPublicInstance();
invariant(inst != null, 'Stateless function components cannot have refs.');
+ var componentInstance = component.getPublicInstance();
+ invariant(componentInstance != null, 'Stateless function components cannot be given refs.');
var refs = inst.refs === emptyObject ? (inst.refs = {}) : inst.refs;
- refs[ref] = component.getPublicInstance();
+ refs[ref] = componentInstance;
},
/**
diff --git a/src/renderers/shared/reconciler/__tests__/ReactStatelessComponent-test.js b/src/renderers/shared/reconciler/__tests__/ReactStatelessComponent-test.js
index c94c60f827..4c07358a2a 100644
--- a/src/renderers/shared/reconciler/__tests__/ReactStatelessComponent-test.js
+++ b/src/renderers/shared/reconciler/__tests__/ReactStatelessComponent-test.js
@@ -125,6 +125,20 @@ describe('ReactStatelessComponent', function() {
);
});
+ it('should throw when given a ref', function() {
+ var Parent = React.createClass({
+ render: function() {
+ return