Skip to content

Commit

Permalink
WIP Improve error message thrown in Fiber with multiple copies of React
Browse files Browse the repository at this point in the history
**what is the change?:**
Adding an 'invariant' with detailed error message for the problem that
occurs when you load two copies of React with the Fiber reconciler.

WIP:
 - Is there any other likely cause for this error besides two copies of
   React?
 - How can we make the message more clear?

Still TODO:
 - Write a unit test
 - Write a documentation page and create the link to the page, similar
   to https://facebook.github.io/react/warnings/refs-must-have-owner.html

It would also be nice to have a page with instructions on how to fix
common cases of accidental double-loading of React, but we can open a
separate issue on that and let the community do it.

**why make this change?:**
This error comes up relatively often and we want to make things clear
when it happens in v16.0+

**test plan:**
WIP

**issue:**
Fixes facebook#9962
  • Loading branch information
flarnie committed Jul 12, 2017
1 parent 50d905b commit 53886bb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/renderers/shared/fiber/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,12 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
function commitAttachRef(finishedWork: Fiber) {
const ref = finishedWork.ref;
if (ref !== null) {
invariant(
typeof ref === 'function',
'commitAttachRef(...): Expected ref to be a function. ' +
'You may have multiple copies of React loaded. ' +
'(details: https://fb.me/react-expected-ref-to-be-function).',
);
const instance = finishedWork.stateNode;
switch (finishedWork.tag) {
case HostComponent:
Expand Down

0 comments on commit 53886bb

Please sign in to comment.