diff --git a/src/renderers/__tests__/refs-test.js b/src/renderers/__tests__/refs-test.js
index 869dd3c78ce0e..6f16f2fd34e4c 100644
--- a/src/renderers/__tests__/refs-test.js
+++ b/src/renderers/__tests__/refs-test.js
@@ -489,12 +489,28 @@ describe('creating element with ref in constructor', () => {
}
}
- var errorMessage =
+ var devErrorMessage =
'addComponentAsRefTo(...): Only a ReactOwner can have refs. You might ' +
"be adding a ref to a component that was not created inside a component's " +
'`render` method, or you have multiple copies of React loaded ' +
'(details: https://fb.me/react-refs-must-have-owner).';
+ var prodErrorMessage =
+ 'Minified React error #119; visit ' +
+ 'http://facebook.github.io/react/docs/error-decoder.html?invariant=119 for the full message ' +
+ 'or use the non-minified dev environment for full errors and additional helpful warnings.';
+
+ var fiberDevErrorMessage =
+ 'Element ref was specified as a string (p) but no owner was ' +
+ 'set. You may have multiple copies of React loaded. ' +
+ '(details: https://fb.me/react-refs-must-have-owner).';
+
+ var fiberProdErrorMessage =
+ 'Minified React error #149; visit ' +
+ 'http://facebook.github.io/react/docs/error-decoder.html?invariant=149&args[]=p ' +
+ 'for the full message or use the non-minified dev environment for full errors and additional ' +
+ 'helpful warnings.';
+
it('throws an error when __DEV__ = true', () => {
ReactTestUtils = require('react-dom/test-utils');
@@ -504,7 +520,9 @@ describe('creating element with ref in constructor', () => {
try {
expect(function() {
ReactTestUtils.renderIntoDocument();
- }).toThrowError(errorMessage);
+ }).toThrowError(
+ ReactDOMFeatureFlags.useFiber ? fiberDevErrorMessage : devErrorMessage,
+ );
} finally {
__DEV__ = originalDev;
}
@@ -519,7 +537,11 @@ describe('creating element with ref in constructor', () => {
try {
expect(function() {
ReactTestUtils.renderIntoDocument();
- }).toThrowError(errorMessage);
+ }).toThrowError(
+ ReactDOMFeatureFlags.useFiber
+ ? fiberProdErrorMessage
+ : prodErrorMessage,
+ );
} finally {
__DEV__ = originalDev;
}
diff --git a/src/renderers/shared/fiber/ReactFiberCommitWork.js b/src/renderers/shared/fiber/ReactFiberCommitWork.js
index a5518140e3719..d6ed708926b45 100644
--- a/src/renderers/shared/fiber/ReactFiberCommitWork.js
+++ b/src/renderers/shared/fiber/ReactFiberCommitWork.js
@@ -562,7 +562,7 @@ module.exports = function(
function commitAttachRef(finishedWork: Fiber) {
const ref = finishedWork.ref;
- if (typeof ref === 'function') {
+ if (ref !== null) {
const instance = finishedWork.stateNode;
switch (finishedWork.tag) {
case HostComponent:
@@ -571,14 +571,6 @@ module.exports = function(
default:
ref(instance);
}
- } else {
- invariant(
- false,
- 'addComponentAsRefTo(...): Only a ReactOwner can have refs. You might ' +
- "be adding a ref to a component that was not created inside a component's " +
- '`render` method, or you have multiple copies of React loaded ' +
- '(details: https://fb.me/react-refs-must-have-owner).',
- );
}
}