From 53886bb4634e656dffd8ea2062aa1f42cbc43083 Mon Sep 17 00:00:00 2001 From: Flarnie Marchan Date: Tue, 11 Jul 2017 18:03:29 -0700 Subject: [PATCH] WIP Improve error message thrown in Fiber with multiple copies of React **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 #9962 --- src/renderers/shared/fiber/ReactFiberCommitWork.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/renderers/shared/fiber/ReactFiberCommitWork.js b/src/renderers/shared/fiber/ReactFiberCommitWork.js index 23a0230e06541..a8b25935471bb 100644 --- a/src/renderers/shared/fiber/ReactFiberCommitWork.js +++ b/src/renderers/shared/fiber/ReactFiberCommitWork.js @@ -557,6 +557,12 @@ module.exports = function( 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: