diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt
index 6135f4f38c8b5..71306da17e9ac 100644
--- a/scripts/fiber/tests-passing.txt
+++ b/scripts/fiber/tests-passing.txt
@@ -626,6 +626,8 @@ src/renderers/__tests__/refs-test.js
* attaches, detaches from fiber component with stack layer
* attaches, detaches from stack component with fiber layer
* attaches and detaches root refs
+* throws an error when __DEV__ = true
+* throws an error when __DEV__ = false
src/renderers/art/__tests__/ReactART-test.js
* should have the correct lifecycle state
diff --git a/src/renderers/__tests__/refs-test.js b/src/renderers/__tests__/refs-test.js
index 6e4c8141f8373..6f16f2fd34e4c 100644
--- a/src/renderers/__tests__/refs-test.js
+++ b/src/renderers/__tests__/refs-test.js
@@ -476,3 +476,74 @@ describe('root level refs', () => {
}
});
});
+
+describe('creating element with ref in constructor', () => {
+ class RefTest extends React.Component {
+ constructor(props) {
+ super(props);
+ this.p =
Hello!
;
+ }
+
+ render() {
+ return {this.p}
;
+ }
+ }
+
+ 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');
+
+ var originalDev = __DEV__;
+ __DEV__ = true;
+
+ try {
+ expect(function() {
+ ReactTestUtils.renderIntoDocument();
+ }).toThrowError(
+ ReactDOMFeatureFlags.useFiber ? fiberDevErrorMessage : devErrorMessage,
+ );
+ } finally {
+ __DEV__ = originalDev;
+ }
+ });
+
+ it('throws an error when __DEV__ = false', () => {
+ ReactTestUtils = require('react-dom/test-utils');
+
+ var originalDev = __DEV__;
+ __DEV__ = false;
+
+ try {
+ expect(function() {
+ ReactTestUtils.renderIntoDocument();
+ }).toThrowError(
+ ReactDOMFeatureFlags.useFiber
+ ? fiberProdErrorMessage
+ : prodErrorMessage,
+ );
+ } finally {
+ __DEV__ = originalDev;
+ }
+ });
+});
diff --git a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
index f85aa6ed4980d..52a4b08c8881d 100644
--- a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
+++ b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
@@ -402,7 +402,7 @@ var ReactCompositeComponent = {
publicContext,
updateQueue,
) {
- if (__DEV__) {
+ if (__DEV__ && !doConstruct) {
ReactCurrentOwner.current = this;
ReactDebugCurrentFrame.getCurrentStack =
ReactDebugCurrentStack.getStackAddendum;