diff --git a/src/renderers/shared/fiber/ReactFiberContext.js b/src/renderers/shared/fiber/ReactFiberContext.js index fb0d4dda3ade9..b6a92cd2341fa 100644 --- a/src/renderers/shared/fiber/ReactFiberContext.js +++ b/src/renderers/shared/fiber/ReactFiberContext.js @@ -89,7 +89,13 @@ exports.getMaskedContext = function( if (__DEV__) { const name = getComponentName(workInProgress) || 'Unknown'; - ReactDebugCurrentFiber.setCurrentFiber(workInProgress, null); + if (workInProgress !== ReactDebugCurrentFiber.current) { + warning( + false, + 'Expected the work in progress to match the currently processed fiber. ' + + 'This error is likely caused by a bug in React. Please file an issue.' + ); + } checkPropTypes( contextTypes, context, @@ -97,7 +103,6 @@ exports.getMaskedContext = function( name, ReactDebugCurrentFiber.getCurrentFiberStackAddendum, ); - ReactDebugCurrentFiber.resetCurrentFiber(); } // Cache unmasked context so we can avoid recreating masked context unless necessary. @@ -184,11 +189,16 @@ function processChildContext( let childContext; if (__DEV__) { + // TODO: we only have to store the "previous" fiber and phase and restore them + // because this method can be called outside of reconciliation. We can remove this + // when we stop supporting unstable_renderSubtreeIntoContainer. + const previousCurrentFiber = ReactDebugCurrentFiber.current; + const previousCurrentPhase = ReactDebugCurrentFiber.phase; ReactDebugCurrentFiber.setCurrentFiber(fiber, 'getChildContext'); startPhaseTimer(fiber, 'getChildContext'); childContext = instance.getChildContext(); stopPhaseTimer(); - ReactDebugCurrentFiber.resetCurrentFiber(); + ReactDebugCurrentFiber.setCurrentFiber(previousCurrentFiber, previousCurrentPhase); } else { childContext = instance.getChildContext(); } @@ -208,6 +218,11 @@ function processChildContext( // assume anything about the given fiber. We won't pass it down if we aren't sure. // TODO: remove this hack when we delete unstable_renderSubtree in Fiber. const workInProgress = isReconciling ? fiber : null; + // TODO: we only have to store the "previous" fiber and phase and restore them + // because this method can be called outside of reconciliation. We can remove this + // when we stop supporting unstable_renderSubtreeIntoContainer. + const previousCurrentFiber = ReactDebugCurrentFiber.current; + const previousCurrentPhase = ReactDebugCurrentFiber.phase; ReactDebugCurrentFiber.setCurrentFiber(workInProgress, null); checkPropTypes( childContextTypes, @@ -216,7 +231,7 @@ function processChildContext( name, ReactDebugCurrentFiber.getCurrentFiberStackAddendum, ); - ReactDebugCurrentFiber.resetCurrentFiber(); + ReactDebugCurrentFiber.setCurrentFiber(previousCurrentFiber, previousCurrentPhase); } return {...parentContext, ...childContext};