From 2f3df5f0b3dea452cd64508f760ff8684f7ce971 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Tue, 7 Feb 2017 13:49:55 -0800 Subject: [PATCH 1/6] Warn about setState in render --- scripts/fiber/tests-passing-except-dev.txt | 1 - scripts/fiber/tests-passing.txt | 1 + .../shared/fiber/ReactFiberScheduler.js | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/fiber/tests-passing-except-dev.txt b/scripts/fiber/tests-passing-except-dev.txt index e5eb1addeffdf..525db56f42681 100644 --- a/scripts/fiber/tests-passing-except-dev.txt +++ b/scripts/fiber/tests-passing-except-dev.txt @@ -106,7 +106,6 @@ src/renderers/__tests__/ReactComponentTreeHook-test.native.js * does not report top-level wrapper as a root src/renderers/__tests__/ReactCompositeComponent-test.js -* should warn about `setState` in render * should warn about `setState` in getChildContext * should disallow nested render calls diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index 525a558660253..70888b000243b 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -577,6 +577,7 @@ src/renderers/__tests__/ReactCompositeComponent-test.js * should warn about `forceUpdate` on unmounted components * should warn about `setState` on unmounted components * should silently allow `setState`, not call cb on unmounting components +* should warn about `setState` in render * should cleanup even if render() fatals * should call componentWillUnmount before unmounting * should warn when shouldComponentUpdate() returns undefined diff --git a/src/renderers/shared/fiber/ReactFiberScheduler.js b/src/renderers/shared/fiber/ReactFiberScheduler.js index 258a254fab613..9d4e3f36f2f60 100644 --- a/src/renderers/shared/fiber/ReactFiberScheduler.js +++ b/src/renderers/shared/fiber/ReactFiberScheduler.js @@ -102,6 +102,16 @@ if (__DEV__) { ctor && (ctor.displayName || ctor.name) || 'ReactClass' ); }; + + var warnAboutUpdateInRender = function(instance : ReactClass) { + warning( + ReactCurrentOwner.current == null, + '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`.' + ); + }; } var timeHeuristicForUnitOfWork = 1; @@ -1102,6 +1112,13 @@ module.exports = function(config : HostConfig Date: Tue, 7 Feb 2017 14:19:45 -0800 Subject: [PATCH 2/6] Warn about setState inside getChildContext Stack uses a module called ReactInvalidSetStateWarningHook, but all it does is warn about setState inside getChildContext. Doesn't seem worth keeping around, so I didn't use it for Fiber, but if I'm mistaken I'll change it. --- scripts/fiber/tests-passing-except-dev.txt | 1 - scripts/fiber/tests-passing.txt | 1 + .../shared/fiber/ReactFiberContext.js | 24 +++++++++++++++ .../shared/fiber/ReactFiberScheduler.js | 30 +++++++++++++------ 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/scripts/fiber/tests-passing-except-dev.txt b/scripts/fiber/tests-passing-except-dev.txt index 525db56f42681..c09ad7f20d879 100644 --- a/scripts/fiber/tests-passing-except-dev.txt +++ b/scripts/fiber/tests-passing-except-dev.txt @@ -106,7 +106,6 @@ src/renderers/__tests__/ReactComponentTreeHook-test.native.js * does not report top-level wrapper as a root src/renderers/__tests__/ReactCompositeComponent-test.js -* should warn about `setState` in getChildContext * should disallow nested render calls src/renderers/__tests__/ReactHostOperationHistoryHook-test.js diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index 70888b000243b..d4c3b623a1c99 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -578,6 +578,7 @@ src/renderers/__tests__/ReactCompositeComponent-test.js * should warn about `setState` on unmounted components * should silently allow `setState`, not call cb on unmounting components * should warn about `setState` in render +* should warn about `setState` in getChildContext * should cleanup even if render() fatals * should call componentWillUnmount before unmounting * should warn when shouldComponentUpdate() returns undefined diff --git a/src/renderers/shared/fiber/ReactFiberContext.js b/src/renderers/shared/fiber/ReactFiberContext.js index 836bc79eb426a..a94ebf77e889d 100644 --- a/src/renderers/shared/fiber/ReactFiberContext.js +++ b/src/renderers/shared/fiber/ReactFiberContext.js @@ -47,6 +47,21 @@ 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) { @@ -144,6 +159,10 @@ 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; @@ -189,6 +208,11 @@ function processChildContext(fiber : Fiber, parentContext : Object, isReconcilin checkReactTypeSpec(childContextTypes, childContext, 'child context', name); 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 9d4e3f36f2f60..8d60e0e336e1c 100644 --- a/src/renderers/shared/fiber/ReactFiberScheduler.js +++ b/src/renderers/shared/fiber/ReactFiberScheduler.js @@ -90,6 +90,10 @@ if (__DEV__) { var warning = require('warning'); var ReactFiberInstrumentation = require('ReactFiberInstrumentation'); var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber'); + var { + isProcessingChildContext, + onEndProcessingChildContext, + } = require('ReactFiberContext'); var warnAboutUpdateOnUnmounted = function(instance : ReactClass) { const ctor = instance.constructor; @@ -103,14 +107,21 @@ if (__DEV__) { ); }; - var warnAboutUpdateInRender = function(instance : ReactClass) { - warning( - ReactCurrentOwner.current == null, - '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`.' - ); + var warnAboutInvalidUpdates = function(instance : ReactClass) { + if (isProcessingChildContext()) { + warning( + false, + 'setState(...): Cannot call setState() inside getChildContext()', + ); + } else if (ReactCurrentOwner.current != null) { + 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`.' + ); + } }; } @@ -869,6 +880,7 @@ module.exports = function(config : HostConfig(config : HostConfig Date: Tue, 7 Feb 2017 14:34:41 -0800 Subject: [PATCH 3/6] Warn about nested renders --- scripts/fiber/tests-passing-except-dev.txt | 3 --- scripts/fiber/tests-passing.txt | 1 + .../__tests__/ReactCompositeComponent-test.js | 10 +++++----- .../shared/fiber/ReactFiberReconciler.js | 18 ++++++++++++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/scripts/fiber/tests-passing-except-dev.txt b/scripts/fiber/tests-passing-except-dev.txt index c09ad7f20d879..db9abfa455fa7 100644 --- a/scripts/fiber/tests-passing-except-dev.txt +++ b/scripts/fiber/tests-passing-except-dev.txt @@ -105,9 +105,6 @@ src/renderers/__tests__/ReactComponentTreeHook-test.native.js * reports update counts * does not report top-level wrapper as a root -src/renderers/__tests__/ReactCompositeComponent-test.js -* should disallow nested render calls - src/renderers/__tests__/ReactHostOperationHistoryHook-test.js * gets recorded for host roots * gets recorded for composite roots diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index d4c3b623a1c99..ca9ae8de0d6b2 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -591,6 +591,7 @@ src/renderers/__tests__/ReactCompositeComponent-test.js * should pass context when re-rendered * unmasked context propagates through updates * should trigger componentWillReceiveProps for context changes +* should disallow nested render calls * only renders once if updated in componentWillReceiveProps * only renders once if updated in componentWillReceiveProps when batching * should update refs if shouldComponentUpdate gives false diff --git a/src/renderers/__tests__/ReactCompositeComponent-test.js b/src/renderers/__tests__/ReactCompositeComponent-test.js index ff58a2465ccb9..03ad27e560b25 100644 --- a/src/renderers/__tests__/ReactCompositeComponent-test.js +++ b/src/renderers/__tests__/ReactCompositeComponent-test.js @@ -1028,11 +1028,11 @@ describe('ReactCompositeComponent', () => { ReactTestUtils.renderIntoDocument(); expectDev(console.error.calls.count()).toBe(1); - expectDev(console.error.calls.argsFor(0)[0]).toBe( - 'Warning: _renderNewRootComponent(): Render methods should ' + - 'be a pure function of props and state; triggering nested component ' + - 'updates from render is not allowed. If necessary, trigger nested ' + - 'updates in componentDidUpdate.\n\nCheck the render method of Outer.' + expectDev(console.error.calls.argsFor(0)[0]).toMatch( + 'Render methods should be a pure function of props and state; ' + + 'triggering nested component updates from render is not allowed. If ' + + 'necessary, trigger nested updates in componentDidUpdate.\n\nCheck the ' + + 'render method of Outer.' ); }); diff --git a/src/renderers/shared/fiber/ReactFiberReconciler.js b/src/renderers/shared/fiber/ReactFiberReconciler.js index 00bb5b7d85688..5d369927919d1 100644 --- a/src/renderers/shared/fiber/ReactFiberReconciler.js +++ b/src/renderers/shared/fiber/ReactFiberReconciler.js @@ -32,6 +32,9 @@ var ReactFiberScheduler = require('ReactFiberScheduler'); if (__DEV__) { var warning = require('warning'); var ReactFiberInstrumentation = require('ReactFiberInstrumentation'); + var warning = require('warning'); + var ReactCurrentOwner = require('ReactCurrentOwner'); + var { getComponentName } = require('ReactFiberTreeReflection'); } var { findCurrentHostFiber } = require('ReactFiberTreeReflection'); @@ -144,6 +147,21 @@ module.exports = function( } = ReactFiberScheduler(config); function scheduleTopLevelUpdate(current : Fiber, element : ReactNodeList, callback : ?Function) { + if (__DEV__) { + const owner = ReactCurrentOwner.current; + if (owner && typeof owner.tag === 'number') { + const ownerFiber : Fiber = (owner : any); + warning( + false, + 'Render methods should be a pure function of props and state; ' + + 'triggering nested component updates from render is not allowed. ' + + 'If necessary, trigger nested updates in componentDidUpdate.\n\n' + + 'Check the render method of %s.', + getComponentName(ownerFiber) + ); + } + } + const priorityLevel = getPriorityContext(); const nextState = { element }; callback = callback === undefined ? null : callback; From 309dea5b4c77f267734f3ddbf852929f2c64c061 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Wed, 22 Feb 2017 13:38:14 -0800 Subject: [PATCH 4/6] Track which lifecycle method we're in during DEV Use this to detect setState inside of render instead of relying on the owner. --- .../shared/fiber/ReactFiberBeginWork.js | 16 ++++++++++++- .../shared/fiber/ReactFiberReconciler.js | 10 ++++---- .../shared/fiber/ReactFiberScheduler.js | 5 +++- .../fiber/isomorphic/ReactDebugLifeCycle.js | 24 +++++++++++++++++++ 4 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 src/renderers/shared/fiber/isomorphic/ReactDebugLifeCycle.js diff --git a/src/renderers/shared/fiber/ReactFiberBeginWork.js b/src/renderers/shared/fiber/ReactFiberBeginWork.js index 73c4870a3009e..7b6d8dc78dcc3 100644 --- a/src/renderers/shared/fiber/ReactFiberBeginWork.js +++ b/src/renderers/shared/fiber/ReactFiberBeginWork.js @@ -66,6 +66,7 @@ var invariant = require('invariant'); if (__DEV__) { var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber'); + var ReactDebugLifeCycle = require('ReactDebugLifeCycle'); var warning = require('warning'); var warnedAboutStatelessRefs = {}; } @@ -230,7 +231,11 @@ module.exports = function( if (__DEV__) { ReactCurrentOwner.current = workInProgress; + ReactDebugLifeCycle.current = workInProgress; + ReactDebugLifeCycle.phase = 'render'; nextChildren = fn(nextProps, context); + ReactDebugLifeCycle.current = null; + ReactDebugLifeCycle.phase = null; } else { nextChildren = fn(nextProps, context); } @@ -279,7 +284,16 @@ module.exports = function( // Rerender ReactCurrentOwner.current = workInProgress; - const nextChildren = instance.render(); + let nextChildren; + if (__DEV__) { + ReactDebugLifeCycle.current = workInProgress; + ReactDebugLifeCycle.phase = 'render'; + nextChildren = instance.render(); + ReactDebugLifeCycle.current = null; + ReactDebugLifeCycle.phase = null; + } else { + nextChildren = instance.render(); + } reconcileChildren(current, workInProgress, nextChildren); // Memoize props and state using the values we just used to render. // TODO: Restructure so we never read values from the instance. diff --git a/src/renderers/shared/fiber/ReactFiberReconciler.js b/src/renderers/shared/fiber/ReactFiberReconciler.js index 5d369927919d1..ede6832440467 100644 --- a/src/renderers/shared/fiber/ReactFiberReconciler.js +++ b/src/renderers/shared/fiber/ReactFiberReconciler.js @@ -33,7 +33,7 @@ if (__DEV__) { var warning = require('warning'); var ReactFiberInstrumentation = require('ReactFiberInstrumentation'); var warning = require('warning'); - var ReactCurrentOwner = require('ReactCurrentOwner'); + var ReactDebugLifeCycle = require('ReactDebugLifeCycle'); var { getComponentName } = require('ReactFiberTreeReflection'); } @@ -148,16 +148,14 @@ module.exports = function( function scheduleTopLevelUpdate(current : Fiber, element : ReactNodeList, callback : ?Function) { if (__DEV__) { - const owner = ReactCurrentOwner.current; - if (owner && typeof owner.tag === 'number') { - const ownerFiber : Fiber = (owner : any); + if (ReactDebugLifeCycle.current !== null) { warning( - false, + ReactDebugLifeCycle.phase !== 'render', 'Render methods should be a pure function of props and state; ' + 'triggering nested component updates from render is not allowed. ' + 'If necessary, trigger nested updates in componentDidUpdate.\n\n' + 'Check the render method of %s.', - getComponentName(ownerFiber) + getComponentName(ReactDebugLifeCycle.current) ); } } diff --git a/src/renderers/shared/fiber/ReactFiberScheduler.js b/src/renderers/shared/fiber/ReactFiberScheduler.js index 8d60e0e336e1c..d90dedcb0d57d 100644 --- a/src/renderers/shared/fiber/ReactFiberScheduler.js +++ b/src/renderers/shared/fiber/ReactFiberScheduler.js @@ -90,6 +90,7 @@ if (__DEV__) { var warning = require('warning'); var ReactFiberInstrumentation = require('ReactFiberInstrumentation'); var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber'); + var ReactDebugLifeCycle = require('ReactDebugLifeCycle'); var { isProcessingChildContext, onEndProcessingChildContext, @@ -113,7 +114,7 @@ if (__DEV__) { false, 'setState(...): Cannot call setState() inside getChildContext()', ); - } else if (ReactCurrentOwner.current != null) { + } else if (ReactDebugLifeCycle.phase === 'render') { warning( false, 'Cannot update during an existing state transition (such as within ' + @@ -880,6 +881,8 @@ module.exports = function(config : HostConfig Date: Wed, 22 Feb 2017 14:02:44 -0800 Subject: [PATCH 5/6] Use ReactDebugLifeCycle to track if we're inside getChildContext --- .../shared/fiber/ReactFiberContext.js | 35 ++++++------------- .../shared/fiber/ReactFiberScheduler.js | 34 +++++++++--------- .../fiber/isomorphic/ReactDebugLifeCycle.js | 2 +- 3 files changed, 28 insertions(+), 43 deletions(-) diff --git a/src/renderers/shared/fiber/ReactFiberContext.js b/src/renderers/shared/fiber/ReactFiberContext.js index a94ebf77e889d..f29b96378ad6b 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 d90dedcb0d57d..08f08c9fe5ea0 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 Date: Thu, 23 Feb 2017 13:33:17 -0800 Subject: [PATCH 6/6] Consolidate ReactCurrentFiber and ReactDebugLifeCycle --- .../shared/fiber/ReactDebugCurrentFiber.js | 4 ++++ .../shared/fiber/ReactFiberBeginWork.js | 13 ++++------ .../shared/fiber/ReactFiberContext.js | 8 +++---- .../shared/fiber/ReactFiberReconciler.js | 9 ++++--- .../shared/fiber/ReactFiberScheduler.js | 6 ++--- .../fiber/isomorphic/ReactDebugLifeCycle.js | 24 ------------------- 6 files changed, 17 insertions(+), 47 deletions(-) delete mode 100644 src/renderers/shared/fiber/isomorphic/ReactDebugLifeCycle.js diff --git a/src/renderers/shared/fiber/ReactDebugCurrentFiber.js b/src/renderers/shared/fiber/ReactDebugCurrentFiber.js index d857e5f2dd36b..6969cec6585ab 100644 --- a/src/renderers/shared/fiber/ReactDebugCurrentFiber.js +++ b/src/renderers/shared/fiber/ReactDebugCurrentFiber.js @@ -14,6 +14,8 @@ import type { Fiber } from 'ReactFiber'; +type LifeCyclePhase = 'render' | 'getChildContext'; + if (__DEV__) { var getComponentName = require('getComponentName'); var { getStackAddendumByWorkInProgressFiber } = require('ReactComponentTreeHook'); @@ -47,6 +49,8 @@ function getCurrentFiberStackAddendum() : string | null { var ReactDebugCurrentFiber = { current: (null : Fiber | null), + phase: (null : LifeCyclePhase | null), + getCurrentFiberOwnerName, getCurrentFiberStackAddendum, }; diff --git a/src/renderers/shared/fiber/ReactFiberBeginWork.js b/src/renderers/shared/fiber/ReactFiberBeginWork.js index 7b6d8dc78dcc3..b88be76bf0edf 100644 --- a/src/renderers/shared/fiber/ReactFiberBeginWork.js +++ b/src/renderers/shared/fiber/ReactFiberBeginWork.js @@ -66,7 +66,6 @@ var invariant = require('invariant'); if (__DEV__) { var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber'); - var ReactDebugLifeCycle = require('ReactDebugLifeCycle'); var warning = require('warning'); var warnedAboutStatelessRefs = {}; } @@ -231,11 +230,9 @@ module.exports = function( if (__DEV__) { ReactCurrentOwner.current = workInProgress; - ReactDebugLifeCycle.current = workInProgress; - ReactDebugLifeCycle.phase = 'render'; + ReactDebugCurrentFiber.phase = 'render'; nextChildren = fn(nextProps, context); - ReactDebugLifeCycle.current = null; - ReactDebugLifeCycle.phase = null; + ReactDebugCurrentFiber.phase = null; } else { nextChildren = fn(nextProps, context); } @@ -286,11 +283,9 @@ module.exports = function( ReactCurrentOwner.current = workInProgress; let nextChildren; if (__DEV__) { - ReactDebugLifeCycle.current = workInProgress; - ReactDebugLifeCycle.phase = 'render'; + ReactDebugCurrentFiber.phase = 'render'; nextChildren = instance.render(); - ReactDebugLifeCycle.current = null; - ReactDebugLifeCycle.phase = null; + ReactDebugCurrentFiber.phase = null; } else { nextChildren = instance.render(); } diff --git a/src/renderers/shared/fiber/ReactFiberContext.js b/src/renderers/shared/fiber/ReactFiberContext.js index f29b96378ad6b..dbb7a43bd9938 100644 --- a/src/renderers/shared/fiber/ReactFiberContext.js +++ b/src/renderers/shared/fiber/ReactFiberContext.js @@ -35,7 +35,7 @@ const { if (__DEV__) { var checkReactTypeSpec = require('checkReactTypeSpec'); var ReactDebugCurrentFrame = require('ReactDebugCurrentFrame'); - var ReactDebugLifeCycle = require('ReactDebugLifeCycle'); + var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber'); var warnedAboutMissingGetChildContext = {}; } @@ -171,11 +171,9 @@ function processChildContext(fiber : Fiber, parentContext : Object, isReconcilin let childContext; if (__DEV__) { - ReactDebugLifeCycle.current = fiber; - ReactDebugLifeCycle.phase = 'getChildContext'; + ReactDebugCurrentFiber.phase = 'getChildContext'; childContext = instance.getChildContext(); - ReactDebugLifeCycle.current = null; - ReactDebugLifeCycle.phase = null; + ReactDebugCurrentFiber.phase = null; } else { childContext = instance.getChildContext(); } diff --git a/src/renderers/shared/fiber/ReactFiberReconciler.js b/src/renderers/shared/fiber/ReactFiberReconciler.js index ede6832440467..3f910aa1d9af2 100644 --- a/src/renderers/shared/fiber/ReactFiberReconciler.js +++ b/src/renderers/shared/fiber/ReactFiberReconciler.js @@ -32,8 +32,7 @@ var ReactFiberScheduler = require('ReactFiberScheduler'); if (__DEV__) { var warning = require('warning'); var ReactFiberInstrumentation = require('ReactFiberInstrumentation'); - var warning = require('warning'); - var ReactDebugLifeCycle = require('ReactDebugLifeCycle'); + var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber'); var { getComponentName } = require('ReactFiberTreeReflection'); } @@ -148,14 +147,14 @@ module.exports = function( function scheduleTopLevelUpdate(current : Fiber, element : ReactNodeList, callback : ?Function) { if (__DEV__) { - if (ReactDebugLifeCycle.current !== null) { + if (ReactDebugCurrentFiber.current !== null) { warning( - ReactDebugLifeCycle.phase !== 'render', + ReactDebugCurrentFiber.phase !== 'render', 'Render methods should be a pure function of props and state; ' + 'triggering nested component updates from render is not allowed. ' + 'If necessary, trigger nested updates in componentDidUpdate.\n\n' + 'Check the render method of %s.', - getComponentName(ReactDebugLifeCycle.current) + getComponentName(ReactDebugCurrentFiber.current) ); } } diff --git a/src/renderers/shared/fiber/ReactFiberScheduler.js b/src/renderers/shared/fiber/ReactFiberScheduler.js index 08f08c9fe5ea0..f0b8601da34ca 100644 --- a/src/renderers/shared/fiber/ReactFiberScheduler.js +++ b/src/renderers/shared/fiber/ReactFiberScheduler.js @@ -90,7 +90,6 @@ if (__DEV__) { var warning = require('warning'); var ReactFiberInstrumentation = require('ReactFiberInstrumentation'); var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber'); - var ReactDebugLifeCycle = require('ReactDebugLifeCycle'); var warnAboutUpdateOnUnmounted = function(instance : ReactClass) { const ctor = instance.constructor; @@ -105,7 +104,7 @@ if (__DEV__) { }; var warnAboutInvalidUpdates = function(instance : ReactClass) { - switch (ReactDebugLifeCycle.phase) { + switch (ReactDebugCurrentFiber.phase) { case 'getChildContext': warning( false, @@ -880,8 +879,7 @@ module.exports = function(config : HostConfig