Skip to content

Commit

Permalink
Reverted ref check in Fiber renderer and updated tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
iansu committed Aug 12, 2017
1 parent 5614fad commit 321f850
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
28 changes: 25 additions & 3 deletions src/renderers/__tests__/refs-test.js
Expand Up @@ -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');

Expand All @@ -504,7 +520,9 @@ describe('creating element with ref in constructor', () => {
try {
expect(function() {
ReactTestUtils.renderIntoDocument(<RefTest />);
}).toThrowError(errorMessage);
}).toThrowError(
ReactDOMFeatureFlags.useFiber ? fiberDevErrorMessage : devErrorMessage,
);
} finally {
__DEV__ = originalDev;
}
Expand All @@ -519,7 +537,11 @@ describe('creating element with ref in constructor', () => {
try {
expect(function() {
ReactTestUtils.renderIntoDocument(<RefTest />);
}).toThrowError(errorMessage);
}).toThrowError(
ReactDOMFeatureFlags.useFiber
? fiberProdErrorMessage
: prodErrorMessage,
);
} finally {
__DEV__ = originalDev;
}
Expand Down
10 changes: 1 addition & 9 deletions src/renderers/shared/fiber/ReactFiberCommitWork.js
Expand Up @@ -562,7 +562,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(

function commitAttachRef(finishedWork: Fiber) {
const ref = finishedWork.ref;
if (typeof ref === 'function') {
if (ref !== null) {
const instance = finishedWork.stateNode;
switch (finishedWork.tag) {
case HostComponent:
Expand All @@ -571,14 +571,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
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).',
);
}
}

Expand Down

0 comments on commit 321f850

Please sign in to comment.