diff --git a/src/renderers/shared/fiber/ReactFiberContext.js b/src/renderers/shared/fiber/ReactFiberContext.js index a94ebf77e8..f29b96378a 100644 --- a/src/renderers/shared/fiber/ReactFiberContext.js +++ b/src/renderers/shared/fiber/ReactFiberContext.js @@ -35,6 +35,7 @@ const { if (__DEV__) { var checkReactTypeSpec = require('checkReactTypeSpec'); var ReactDebugCurrentFrame = require('ReactDebugCurrentFrame'); + var ReactDebugLifeCycle = require('ReactDebugLifeCycle'); var warnedAboutMissingGetChildContext = {}; } @@ -47,21 +48,6 @@ let didPerformWorkStackCursor : StackCursor = createCursor(false); // pushed the next context provider, and now need to merge their contexts. let previousContext : Object = emptyObject; -if (__DEV__) { - var _isProcessingChildContext = false; - var onBeginProcessingChildContext = function() { - _isProcessingChildContext = true; - }; - exports.onBeginProcessingChildContext = onBeginProcessingChildContext; - var onEndProcessingChildContext = function() { - _isProcessingChildContext = false; - }; - exports.onEndProcessingChildContext = onEndProcessingChildContext; - exports.isProcessingChildContext = function() : boolean { - return _isProcessingChildContext; - }; -} - function getUnmaskedContext(workInProgress : Fiber) : Object { const hasOwnContext = isContextProvider(workInProgress); if (hasOwnContext) { @@ -159,10 +145,6 @@ exports.pushTopLevelContextObject = function(fiber : Fiber, context : Object, di }; function processChildContext(fiber : Fiber, parentContext : Object, isReconciling : boolean): Object { - if (__DEV__) { - onBeginProcessingChildContext(); - } - const instance = fiber.stateNode; const childContextTypes = fiber.type.childContextTypes; @@ -187,7 +169,16 @@ function processChildContext(fiber : Fiber, parentContext : Object, isReconcilin return parentContext; } - const childContext = instance.getChildContext(); + let childContext; + if (__DEV__) { + ReactDebugLifeCycle.current = fiber; + ReactDebugLifeCycle.phase = 'getChildContext'; + childContext = instance.getChildContext(); + ReactDebugLifeCycle.current = null; + ReactDebugLifeCycle.phase = null; + } else { + childContext = instance.getChildContext(); + } for (let contextKey in childContext) { invariant( contextKey in childContextTypes, @@ -209,10 +200,6 @@ function processChildContext(fiber : Fiber, parentContext : Object, isReconcilin ReactDebugCurrentFrame.current = null; } - if (__DEV__) { - onEndProcessingChildContext(); - } - return {...parentContext, ...childContext}; } exports.processChildContext = processChildContext; diff --git a/src/renderers/shared/fiber/ReactFiberScheduler.js b/src/renderers/shared/fiber/ReactFiberScheduler.js index d90dedcb0d..08f08c9fe5 100644 --- a/src/renderers/shared/fiber/ReactFiberScheduler.js +++ b/src/renderers/shared/fiber/ReactFiberScheduler.js @@ -91,10 +91,6 @@ if (__DEV__) { var ReactFiberInstrumentation = require('ReactFiberInstrumentation'); var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber'); var ReactDebugLifeCycle = require('ReactDebugLifeCycle'); - var { - isProcessingChildContext, - onEndProcessingChildContext, - } = require('ReactFiberContext'); var warnAboutUpdateOnUnmounted = function(instance : ReactClass) { const ctor = instance.constructor; @@ -109,19 +105,22 @@ if (__DEV__) { }; var warnAboutInvalidUpdates = function(instance : ReactClass) { - if (isProcessingChildContext()) { - warning( - false, - 'setState(...): Cannot call setState() inside getChildContext()', - ); - } else if (ReactDebugLifeCycle.phase === 'render') { - warning( - false, - 'Cannot update during an existing state transition (such as within ' + - '`render` or another component\'s constructor). Render methods should ' + - 'be a pure function of props and state; constructor side-effects are ' + - 'an anti-pattern, but can be moved to `componentWillMount`.' - ); + switch (ReactDebugLifeCycle.phase) { + case 'getChildContext': + warning( + false, + 'setState(...): Cannot call setState() inside getChildContext()', + ); + break; + case 'render': + warning( + false, + 'Cannot update during an existing state transition (such as within ' + + '`render` or another component\'s constructor). Render methods should ' + + 'be a pure function of props and state; constructor side-effects are ' + + 'an anti-pattern, but can be moved to `componentWillMount`.' + ); + break; } }; } @@ -883,7 +882,6 @@ module.exports = function(config : HostConfig