From a1ef4c43913c2febcb0eef5d6070b666e81aa233 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Fri, 3 Feb 2017 13:32:09 -0800 Subject: [PATCH 1/3] Replace `throw new Error` with invariant module --- src/renderers/shared/fiber/ReactChildFiber.js | 21 ++++--- .../shared/fiber/ReactFiberBeginWork.js | 42 ++++++++------ .../shared/fiber/ReactFiberClassComponent.js | 21 ++++--- .../shared/fiber/ReactFiberCommitWork.js | 40 ++++++++++---- .../shared/fiber/ReactFiberCompleteWork.js | 49 +++++++++++------ .../shared/fiber/ReactFiberHostContext.js | 23 +++++--- .../shared/fiber/ReactFiberScheduler.js | 55 +++++++++++-------- 7 files changed, 154 insertions(+), 97 deletions(-) diff --git a/src/renderers/shared/fiber/ReactChildFiber.js b/src/renderers/shared/fiber/ReactChildFiber.js index bc0139c88fcc0..4320df60ea776 100644 --- a/src/renderers/shared/fiber/ReactChildFiber.js +++ b/src/renderers/shared/fiber/ReactChildFiber.js @@ -797,17 +797,19 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) { // but using the iterator instead. const iteratorFn = getIteratorFn(newChildrenIterable); - if (typeof iteratorFn !== 'function') { - throw new Error('An object is not an iterable.'); - } + invariant( + typeof iteratorFn === 'function', + 'An object is not an iterable.' + ); if (__DEV__) { // First, validate keys. // We'll get a different iterator later for the main pass. const newChildren = iteratorFn.call(newChildrenIterable); - if (newChildren == null) { - throw new Error('An iterable object provided no iterator.'); - } + invariant( + newChildren != null, + 'An iterable object provided no iterator.' + ); let knownKeys = null; let step = newChildren.next(); for (; !step.done; step = newChildren.next()) { @@ -817,9 +819,10 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) { } const newChildren = iteratorFn.call(newChildrenIterable); - if (newChildren == null) { - throw new Error('An iterable object provided no iterator.'); - } + invariant( + newChildren != null, + 'An iterable object provided no iterator.' + ); let resultingFirstChild : ?Fiber = null; let previousNewFiber : ?Fiber = null; diff --git a/src/renderers/shared/fiber/ReactFiberBeginWork.js b/src/renderers/shared/fiber/ReactFiberBeginWork.js index 8aac659a41ee6..9d3802822b361 100644 --- a/src/renderers/shared/fiber/ReactFiberBeginWork.js +++ b/src/renderers/shared/fiber/ReactFiberBeginWork.js @@ -62,10 +62,11 @@ var { } = require('ReactTypeOfSideEffect'); var ReactCurrentOwner = require('ReactCurrentOwner'); var ReactFiberClassComponent = require('ReactFiberClassComponent'); -var warning = require('warning'); +var invariant = require('invariant'); if (__DEV__) { var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber'); + var warning = require('warning'); var warnedAboutStatelessRefs = {}; } @@ -341,9 +342,10 @@ module.exports = function( // we don't do the bailout and we have to reuse existing props instead. if (nextProps === null) { nextProps = memoizedProps; - if (!nextProps) { - throw new Error('We should always have pending or current props.'); - } + invariant( + nextProps !== null, + 'We should always have pending or current props.' + ); } } else if (nextProps === null || memoizedProps === nextProps) { if (memoizedProps.hidden && @@ -442,9 +444,10 @@ module.exports = function( } function mountIndeterminateComponent(current, workInProgress, priorityLevel) { - if (current) { - throw new Error('An indeterminate component should never have mounted.'); - } + invariant( + current === null, + 'An indeterminate component should never have mounted' + ); var fn = workInProgress.type; var props = workInProgress.pendingProps; var unmaskedContext = getUnmaskedContext(workInProgress); @@ -511,9 +514,10 @@ module.exports = function( // we don't do the bailout and we have to reuse existing props instead. if (nextCoroutine === null) { nextCoroutine = current && current.memoizedProps; - if (!nextCoroutine) { - throw new Error('We should always have pending or current props.'); - } + invariant( + nextCoroutine != null, + 'We should always have pending or current props.' + ); } } else if (nextCoroutine === null || workInProgress.memoizedProps === nextCoroutine) { nextCoroutine = workInProgress.memoizedProps; @@ -575,9 +579,10 @@ module.exports = function( // we don't do the bailout and we have to reuse existing props instead. if (nextChildren === null) { nextChildren = current && current.memoizedProps; - if (!nextChildren) { - throw new Error('We should always have pending or current props.'); - } + invariant( + nextChildren != null, + 'We should always have pending or current props.' + ); } } else if (nextChildren === null || workInProgress.memoizedProps === nextChildren) { return bailoutOnAlreadyFinishedWork(current, workInProgress); @@ -727,15 +732,16 @@ module.exports = function( case Fragment: return updateFragment(current, workInProgress); default: - throw new Error('Unknown unit of work tag'); + invariant(false, 'Unknown unit of work tag'); } } function beginFailedWork(current : ?Fiber, workInProgress : Fiber, priorityLevel : PriorityLevel) { - if (workInProgress.tag !== ClassComponent && - workInProgress.tag !== HostRoot) { - throw new Error('Invalid type of work'); - } + invariant( + workInProgress.tag === ClassComponent || + workInProgress.tag === HostRoot, + 'Invalid type of work' + ); // Add an error effect so we can handle the error during the commit phase workInProgress.effectTag |= Err; diff --git a/src/renderers/shared/fiber/ReactFiberClassComponent.js b/src/renderers/shared/fiber/ReactFiberClassComponent.js index 609662d471b8e..983d41c9a8403 100644 --- a/src/renderers/shared/fiber/ReactFiberClassComponent.js +++ b/src/renderers/shared/fiber/ReactFiberClassComponent.js @@ -257,9 +257,10 @@ module.exports = function( const state = instance.state || null; let props = workInProgress.pendingProps; - if (!props) { - throw new Error('There must be pending props for an initial mount.'); - } + invariant( + props, + 'There must be pending props for an initial mount.' + ); const unmaskedContext = getUnmaskedContext(workInProgress); @@ -298,9 +299,10 @@ module.exports = function( // If there isn't any new props, then we'll reuse the memoized props. // This could be from already completed work. newProps = workInProgress.memoizedProps; - if (!newProps) { - throw new Error('There should always be pending or memoized props.'); - } + invariant( + newProps != null, + 'There should always be pending or memoized props.' + ); } const newUnmaskedContext = getUnmaskedContext(workInProgress); const newContext = getMaskedContext(workInProgress, newUnmaskedContext); @@ -363,9 +365,10 @@ module.exports = function( // If there aren't any new props, then we'll reuse the memoized props. // This could be from already completed work. newProps = oldProps; - if (!newProps) { - throw new Error('There should always be pending or memoized props.'); - } + invariant( + newProps != null, + 'There should always be pending or memoized props.' + ); } const oldContext = instance.context; const newUnmaskedContext = getUnmaskedContext(workInProgress); diff --git a/src/renderers/shared/fiber/ReactFiberCommitWork.js b/src/renderers/shared/fiber/ReactFiberCommitWork.js index 04d24c44f54b5..ca182ac336062 100644 --- a/src/renderers/shared/fiber/ReactFiberCommitWork.js +++ b/src/renderers/shared/fiber/ReactFiberCommitWork.js @@ -34,6 +34,8 @@ var { ContentReset, } = require('ReactTypeOfSideEffect'); +var invariant = require('invariant'); + module.exports = function( config : HostConfig, captureError : (failedFiber : Fiber, error: Error) => ?Fiber @@ -94,7 +96,10 @@ module.exports = function( } parent = parent.return; } - throw new Error('Expected to find a host parent.'); + invariant( + false, + 'Expected to find a host parent.' + ); } function getHostParentFiber(fiber : Fiber) : Fiber { @@ -105,7 +110,10 @@ module.exports = function( } parent = parent.return; } - throw new Error('Expected to find a host parent.'); + invariant( + false, + 'Expected to find a host parent.' + ); } function isHostParent(fiber : Fiber) : boolean { @@ -173,7 +181,10 @@ module.exports = function( parent = parentFiber.stateNode.containerInfo; break; default: - throw new Error('Invalid host parent fiber.'); + invariant( + false, + 'Invalid host parent fiber.' + ); } if (parentFiber.effectTag & ContentReset) { // Reset the text content of the parent before doing any insertions @@ -374,9 +385,10 @@ module.exports = function( return; } case HostText: { - if (finishedWork.stateNode == null || !current) { - throw new Error('This should only be done during updates.'); - } + invariant( + finishedWork.stateNode !== null && current != null, + 'This should only be done during updates.' + ); const textInstance : TI = finishedWork.stateNode; const newText : string = finishedWork.memoizedProps; const oldText : string = current.memoizedProps; @@ -389,8 +401,12 @@ module.exports = function( case HostPortal: { return; } - default: - throw new Error('This unit of work tag should not have side-effects.'); + default: { + invariant( + false, + 'This unit of work tag should not have side-effects.' + ); + } } } @@ -450,8 +466,12 @@ module.exports = function( // We have no life-cycles associated with portals. return; } - default: - throw new Error('This unit of work tag should not have side-effects.'); + default: { + invariant( + false, + 'This unit of work tag should not have side-effects.' + ); + } } } diff --git a/src/renderers/shared/fiber/ReactFiberCompleteWork.js b/src/renderers/shared/fiber/ReactFiberCompleteWork.js index 8b4b89af23b29..eb1df298758a4 100644 --- a/src/renderers/shared/fiber/ReactFiberCompleteWork.js +++ b/src/renderers/shared/fiber/ReactFiberCompleteWork.js @@ -46,6 +46,8 @@ if (__DEV__) { var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber'); } +var invariant = require('invariant'); + module.exports = function( config : HostConfig, hostContext : HostContext, @@ -91,7 +93,10 @@ module.exports = function( while (node) { if (node.tag === HostComponent || node.tag === HostText || node.tag === HostPortal) { - throw new Error('A coroutine cannot have host component children.'); + invariant( + false, + 'A coroutine cannot have host component children.' + ); } else if (node.tag === YieldComponent) { yields.push(node.type); } else if (node.child) { @@ -112,9 +117,10 @@ module.exports = function( function moveCoroutineToHandlerPhase(current : ?Fiber, workInProgress : Fiber) { var coroutine = (workInProgress.memoizedProps : ?ReactCoroutine); - if (!coroutine) { - throw new Error('Should be resolved by now'); - } + invariant( + coroutine, + 'Should be resolved by now' + ); // First step of the coroutine has completed. Now we need to do the second. // TODO: It would be nice to have a multi stage coroutine represented by a @@ -229,12 +235,12 @@ module.exports = function( } } else { if (!newProps) { - if (workInProgress.stateNode === null) { - throw new Error('We must have new props for new mounts.'); - } else { - // This can happen when we abort work. - return null; - } + invariant( + workInProgress.stateNode !== null, + 'We must have new props for new mounts' + ); + // This can happen when we abort work. + return null; } const currentHostContext = getHostContext(); @@ -278,12 +284,12 @@ module.exports = function( } } else { if (typeof newText !== 'string') { - if (workInProgress.stateNode === null) { - throw new Error('We must have new props for new mounts.'); - } else { - // This can happen when we abort work. - return null; - } + invariant( + workInProgress.stateNode !== null, + 'We must have new props for new mounts' + ); + // This can happen when we abort work. + return null; } const rootContainerInstance = getRootHostContainer(); const currentHostContext = getHostContext(); @@ -311,9 +317,16 @@ module.exports = function( // Error cases case IndeterminateComponent: - throw new Error('An indeterminate component should have become determinate before completing.'); + invariant( + false, + 'An indeterminate component should have become determinate before completing.' + ); + // eslint-disable-next-line no-fallthrough default: - throw new Error('Unknown unit of work tag'); + invariant( + false, + 'Unknown unit of work tag' + ); } } diff --git a/src/renderers/shared/fiber/ReactFiberHostContext.js b/src/renderers/shared/fiber/ReactFiberHostContext.js index 1d29b709b6f68..f0c7254ae793b 100644 --- a/src/renderers/shared/fiber/ReactFiberHostContext.js +++ b/src/renderers/shared/fiber/ReactFiberHostContext.js @@ -24,6 +24,8 @@ const { push, } = require('ReactFiberStack'); +const invariant = require('invariant'); + export type HostContext = { getHostContext() : CX, getRootHostContainer() : C, @@ -48,9 +50,10 @@ module.exports = function( function getRootHostContainer() : C { const rootInstance = rootInstanceStackCursor.current; - if (rootInstance == null) { - throw new Error('Expected root container to exist.'); - } + invariant( + rootInstance != null, + 'Expected root container to exist.' + ); return rootInstance; } @@ -75,17 +78,19 @@ module.exports = function( function getHostContext() : CX { const context = contextStackCursor.current; - if (context == null) { - throw new Error('Expected host context to exist.'); - } + invariant( + context != null, + 'Expected host context to exist.' + ); return context; } function pushHostContext(fiber : Fiber) : void { const rootInstance = rootInstanceStackCursor.current; - if (rootInstance == null) { - throw new Error('Expected root host context to exist.'); - } + invariant( + rootInstance != null, + 'Expected root host context to exist.' + ); const context = contextStackCursor.current || emptyObject; const nextContext = getChildHostContext(context, fiber.type, rootInstance); diff --git a/src/renderers/shared/fiber/ReactFiberScheduler.js b/src/renderers/shared/fiber/ReactFiberScheduler.js index cafe85ff7e700..524f21ff67ee4 100644 --- a/src/renderers/shared/fiber/ReactFiberScheduler.js +++ b/src/renderers/shared/fiber/ReactFiberScheduler.js @@ -83,6 +83,8 @@ var { resetContext, } = require('ReactFiberContext'); +var invariant = require('invariant'); + if (__DEV__) { var ReactFiberInstrumentation = require('ReactFiberInstrumentation'); var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber'); @@ -340,12 +342,11 @@ module.exports = function(config : HostConfig(config : HostConfig(config : HostConfig(config : HostConfig(config : HostConfig= HighPriority && !deadline) { - throw new Error( - 'Cannot perform deferred work without a deadline.' - ); - } + invariant( + deadline || (priorityLevel < HighPriority), + 'Cannot perform deferred work without a deadline.' + ); // Before starting any work, check to see if there are any pending // commits from the previous frame. @@ -988,9 +991,10 @@ module.exports = function(config : HostConfig(config : HostConfig Date: Fri, 3 Feb 2017 15:37:30 -0800 Subject: [PATCH 2/3] Get rid of DEV only invariant --- src/renderers/shared/fiber/ReactChildFiber.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/renderers/shared/fiber/ReactChildFiber.js b/src/renderers/shared/fiber/ReactChildFiber.js index 4320df60ea776..c48371a9c7c15 100644 --- a/src/renderers/shared/fiber/ReactChildFiber.js +++ b/src/renderers/shared/fiber/ReactChildFiber.js @@ -806,15 +806,13 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) { // First, validate keys. // We'll get a different iterator later for the main pass. const newChildren = iteratorFn.call(newChildrenIterable); - invariant( - newChildren != null, - 'An iterable object provided no iterator.' - ); - let knownKeys = null; - let step = newChildren.next(); - for (; !step.done; step = newChildren.next()) { - const child = step.value; - knownKeys = warnOnDuplicateKey(child, knownKeys); + if (newChildren) { + let knownKeys = null; + let step = newChildren.next(); + for (; !step.done; step = newChildren.next()) { + const child = step.value; + knownKeys = warnOnDuplicateKey(child, knownKeys); + } } } From 915a3e88a25690bd13e1e740f6de60b698858f82 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Mon, 6 Feb 2017 13:52:05 -0800 Subject: [PATCH 3/3] Add additional message to internal invariants The message tells users that the error is likely due to a bug in React, and that they should file an issue. --- src/renderers/shared/fiber/ReactChildFiber.js | 14 ++++++++--- .../shared/fiber/ReactFiberBeginWork.js | 24 ++++++++++++++----- .../shared/fiber/ReactFiberClassComponent.js | 12 +++++++--- .../shared/fiber/ReactFiberCommitWork.js | 21 +++++++++++----- .../shared/fiber/ReactFiberCompleteWork.js | 18 ++++++++++---- .../shared/fiber/ReactFiberHostContext.js | 12 +++++++--- .../shared/fiber/ReactFiberScheduler.js | 24 +++++++++++++------ 7 files changed, 92 insertions(+), 33 deletions(-) diff --git a/src/renderers/shared/fiber/ReactChildFiber.js b/src/renderers/shared/fiber/ReactChildFiber.js index c48371a9c7c15..68d4f7b39cffc 100644 --- a/src/renderers/shared/fiber/ReactChildFiber.js +++ b/src/renderers/shared/fiber/ReactChildFiber.js @@ -72,6 +72,9 @@ const { Deletion, } = ReactTypeOfSideEffect; +const internalErrorMessage = + 'This error is likely caused by a bug in React. Please file an issue.'; + function coerceRef(current: ?Fiber, element: ReactElement) { let mixedRef = element.ref; if (mixedRef != null && typeof mixedRef !== 'function') { @@ -88,7 +91,11 @@ function coerceRef(current: ?Fiber, element: ReactElement) { inst = (owner : any).getPublicInstance(); } } - invariant(inst, 'Missing owner for string ref %s', mixedRef); + invariant( + inst, 'Missing owner for string ref %s. (%s)', + mixedRef, + internalErrorMessage + ); const stringRef = String(mixedRef); // Check if previous string ref matches new string ref if (current && current.ref && current.ref._stringRef === stringRef) { @@ -799,7 +806,8 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) { const iteratorFn = getIteratorFn(newChildrenIterable); invariant( typeof iteratorFn === 'function', - 'An object is not an iterable.' + 'An object is not an iterable. (%s)', + internalErrorMessage ); if (__DEV__) { @@ -819,7 +827,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) { const newChildren = iteratorFn.call(newChildrenIterable); invariant( newChildren != null, - 'An iterable object provided no iterator.' + 'An iterable object provided no iterator.', ); let resultingFirstChild : ?Fiber = null; diff --git a/src/renderers/shared/fiber/ReactFiberBeginWork.js b/src/renderers/shared/fiber/ReactFiberBeginWork.js index 9d3802822b361..38eb56ca0b587 100644 --- a/src/renderers/shared/fiber/ReactFiberBeginWork.js +++ b/src/renderers/shared/fiber/ReactFiberBeginWork.js @@ -71,6 +71,9 @@ if (__DEV__) { var warnedAboutStatelessRefs = {}; } +const internalErrorMessage = + 'This error is likely caused by a bug in React. Please file an issue.'; + module.exports = function( config : HostConfig, hostContext : HostContext, @@ -344,7 +347,8 @@ module.exports = function( nextProps = memoizedProps; invariant( nextProps !== null, - 'We should always have pending or current props.' + 'We should always have pending or current props. (%s)', + internalErrorMessage ); } } else if (nextProps === null || memoizedProps === nextProps) { @@ -446,7 +450,8 @@ module.exports = function( function mountIndeterminateComponent(current, workInProgress, priorityLevel) { invariant( current === null, - 'An indeterminate component should never have mounted' + 'An indeterminate component should never have mounted. (%s)', + internalErrorMessage ); var fn = workInProgress.type; var props = workInProgress.pendingProps; @@ -516,7 +521,8 @@ module.exports = function( nextCoroutine = current && current.memoizedProps; invariant( nextCoroutine != null, - 'We should always have pending or current props.' + 'We should always have pending or current props. (%s)', + internalErrorMessage ); } } else if (nextCoroutine === null || workInProgress.memoizedProps === nextCoroutine) { @@ -581,7 +587,8 @@ module.exports = function( nextChildren = current && current.memoizedProps; invariant( nextChildren != null, - 'We should always have pending or current props.' + 'We should always have pending or current props. (%s)', + internalErrorMessage ); } } else if (nextChildren === null || workInProgress.memoizedProps === nextChildren) { @@ -732,7 +739,11 @@ module.exports = function( case Fragment: return updateFragment(current, workInProgress); default: - invariant(false, 'Unknown unit of work tag'); + invariant( + false, + 'Unknown unit of work tag. (%s)', + internalErrorMessage + ); } } @@ -740,7 +751,8 @@ module.exports = function( invariant( workInProgress.tag === ClassComponent || workInProgress.tag === HostRoot, - 'Invalid type of work' + 'Invalid type of work. (%s)', + internalErrorMessage ); // Add an error effect so we can handle the error during the commit phase diff --git a/src/renderers/shared/fiber/ReactFiberClassComponent.js b/src/renderers/shared/fiber/ReactFiberClassComponent.js index 983d41c9a8403..d4f7d1f5391b0 100644 --- a/src/renderers/shared/fiber/ReactFiberClassComponent.js +++ b/src/renderers/shared/fiber/ReactFiberClassComponent.js @@ -40,6 +40,9 @@ var invariant = require('invariant'); const isArray = Array.isArray; +const internalErrorMessage = + 'This error is likely caused by a bug in React. Please file an issue.'; + module.exports = function( scheduleUpdate : (fiber : Fiber, priorityLevel : PriorityLevel) => void, getPriorityContext : () => PriorityLevel, @@ -259,7 +262,8 @@ module.exports = function( let props = workInProgress.pendingProps; invariant( props, - 'There must be pending props for an initial mount.' + 'There must be pending props for an initial mount. (%s)', + internalErrorMessage ); const unmaskedContext = getUnmaskedContext(workInProgress); @@ -301,7 +305,8 @@ module.exports = function( newProps = workInProgress.memoizedProps; invariant( newProps != null, - 'There should always be pending or memoized props.' + 'There should always be pending or memoized props. (%s)', + internalErrorMessage ); } const newUnmaskedContext = getUnmaskedContext(workInProgress); @@ -367,7 +372,8 @@ module.exports = function( newProps = oldProps; invariant( newProps != null, - 'There should always be pending or memoized props.' + 'There should always be pending or memoized props. (%s)', + internalErrorMessage ); } const oldContext = instance.context; diff --git a/src/renderers/shared/fiber/ReactFiberCommitWork.js b/src/renderers/shared/fiber/ReactFiberCommitWork.js index ca182ac336062..dd72e78d241f4 100644 --- a/src/renderers/shared/fiber/ReactFiberCommitWork.js +++ b/src/renderers/shared/fiber/ReactFiberCommitWork.js @@ -36,6 +36,9 @@ var { var invariant = require('invariant'); +const internalErrorMessage = + 'This error is likely caused by a bug in React. Please file an issue.'; + module.exports = function( config : HostConfig, captureError : (failedFiber : Fiber, error: Error) => ?Fiber @@ -98,7 +101,8 @@ module.exports = function( } invariant( false, - 'Expected to find a host parent.' + 'Expected to find a host parent. (%s)', + internalErrorMessage ); } @@ -112,7 +116,8 @@ module.exports = function( } invariant( false, - 'Expected to find a host parent.' + 'Expected to find a host parent. (%s)', + internalErrorMessage ); } @@ -183,7 +188,8 @@ module.exports = function( default: invariant( false, - 'Invalid host parent fiber.' + 'Invalid host parent fiber. (%s)', + internalErrorMessage ); } if (parentFiber.effectTag & ContentReset) { @@ -387,7 +393,8 @@ module.exports = function( case HostText: { invariant( finishedWork.stateNode !== null && current != null, - 'This should only be done during updates.' + 'This should only be done during updates. (%s)', + internalErrorMessage ); const textInstance : TI = finishedWork.stateNode; const newText : string = finishedWork.memoizedProps; @@ -404,7 +411,8 @@ module.exports = function( default: { invariant( false, - 'This unit of work tag should not have side-effects.' + 'This unit of work tag should not have side-effects. (%s)', + internalErrorMessage ); } } @@ -469,7 +477,8 @@ module.exports = function( default: { invariant( false, - 'This unit of work tag should not have side-effects.' + 'This unit of work tag should not have side-effects. (%s)', + internalErrorMessage ); } } diff --git a/src/renderers/shared/fiber/ReactFiberCompleteWork.js b/src/renderers/shared/fiber/ReactFiberCompleteWork.js index eb1df298758a4..a3e8fa397baad 100644 --- a/src/renderers/shared/fiber/ReactFiberCompleteWork.js +++ b/src/renderers/shared/fiber/ReactFiberCompleteWork.js @@ -48,6 +48,9 @@ if (__DEV__) { var invariant = require('invariant'); +const internalErrorMessage = + 'This error is likely caused by a bug in React. Please file an issue.'; + module.exports = function( config : HostConfig, hostContext : HostContext, @@ -119,7 +122,8 @@ module.exports = function( var coroutine = (workInProgress.memoizedProps : ?ReactCoroutine); invariant( coroutine, - 'Should be resolved by now' + 'Should be resolved by now. (%s)', + internalErrorMessage ); // First step of the coroutine has completed. Now we need to do the second. @@ -237,7 +241,8 @@ module.exports = function( if (!newProps) { invariant( workInProgress.stateNode !== null, - 'We must have new props for new mounts' + 'We must have new props for new mounts. (%s)', + internalErrorMessage ); // This can happen when we abort work. return null; @@ -286,7 +291,8 @@ module.exports = function( if (typeof newText !== 'string') { invariant( workInProgress.stateNode !== null, - 'We must have new props for new mounts' + 'We must have new props for new mounts. (%s)', + internalErrorMessage ); // This can happen when we abort work. return null; @@ -319,13 +325,15 @@ module.exports = function( case IndeterminateComponent: invariant( false, - 'An indeterminate component should have become determinate before completing.' + 'An indeterminate component should have become determinate before completing. (%s)', + internalErrorMessage ); // eslint-disable-next-line no-fallthrough default: invariant( false, - 'Unknown unit of work tag' + 'Unknown unit of work tag. (%s)', + internalErrorMessage ); } } diff --git a/src/renderers/shared/fiber/ReactFiberHostContext.js b/src/renderers/shared/fiber/ReactFiberHostContext.js index f0c7254ae793b..69c4bb24bdeeb 100644 --- a/src/renderers/shared/fiber/ReactFiberHostContext.js +++ b/src/renderers/shared/fiber/ReactFiberHostContext.js @@ -36,6 +36,9 @@ export type HostContext = { resetHostContainer() : void, }; +const internalErrorMessage = + 'This error is likely caused by a bug in React. Please file an issue.'; + module.exports = function( config : HostConfig ) : HostContext { @@ -52,7 +55,8 @@ module.exports = function( const rootInstance = rootInstanceStackCursor.current; invariant( rootInstance != null, - 'Expected root container to exist.' + 'Expected root container to exist. (%s)', + internalErrorMessage ); return rootInstance; } @@ -80,7 +84,8 @@ module.exports = function( const context = contextStackCursor.current; invariant( context != null, - 'Expected host context to exist.' + 'Expected host context to exist. (%s)', + internalErrorMessage ); return context; } @@ -89,7 +94,8 @@ module.exports = function( const rootInstance = rootInstanceStackCursor.current; invariant( rootInstance != null, - 'Expected root host context to exist.' + 'Expected root host context to exist. (%s)', + internalErrorMessage ); const context = contextStackCursor.current || emptyObject; diff --git a/src/renderers/shared/fiber/ReactFiberScheduler.js b/src/renderers/shared/fiber/ReactFiberScheduler.js index 524f21ff67ee4..41dd8d6152d29 100644 --- a/src/renderers/shared/fiber/ReactFiberScheduler.js +++ b/src/renderers/shared/fiber/ReactFiberScheduler.js @@ -92,6 +92,9 @@ if (__DEV__) { var timeHeuristicForUnitOfWork = 1; +const internalErrorMessage = + 'This error is likely caused by a bug in React. Please file an issue.'; + module.exports = function(config : HostConfig) { const hostContext = ReactFiberHostContext(config); const { popHostContainer, popHostContext, resetHostContainer } = hostContext; @@ -345,7 +348,8 @@ module.exports = function(config : HostConfig(config : HostConfig(config : HostConfig(config : HostConfig(config : HostConfig(config : HostConfig(config : HostConfig