From 7ef856aa3676f898ac5014f77a3e176bdf727350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Wed, 23 Nov 2016 10:59:49 -0800 Subject: [PATCH] Change the behavior to always fail childContextTypes if there is a method (#8391) Even if that method returns falsy values. --- scripts/fiber/tests-failing.txt | 2 -- scripts/fiber/tests-passing-except-dev.txt | 2 ++ src/renderers/shared/fiber/ReactFiberScheduler.js | 3 ++- .../shared/stack/reconciler/ReactCompositeComponent.js | 4 +--- .../reconciler/__tests__/ReactCompositeComponent-test.js | 1 + 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/fiber/tests-failing.txt b/scripts/fiber/tests-failing.txt index 1c87996514..127c7dbfe9 100644 --- a/scripts/fiber/tests-failing.txt +++ b/scripts/fiber/tests-failing.txt @@ -92,8 +92,6 @@ src/renderers/shared/stack/reconciler/__tests__/ReactComponentLifeCycle-test.js * should carry through each of the phases of setup src/renderers/shared/stack/reconciler/__tests__/ReactCompositeComponent-test.js -* should warn about `forceUpdate` on unmounted components -* should warn about `setState` on unmounted components * should warn about `setState` in render * should warn about `setState` in getChildContext * should update refs if shouldComponentUpdate gives false diff --git a/scripts/fiber/tests-passing-except-dev.txt b/scripts/fiber/tests-passing-except-dev.txt index 3e077e6251..a5c87b20ef 100644 --- a/scripts/fiber/tests-passing-except-dev.txt +++ b/scripts/fiber/tests-passing-except-dev.txt @@ -162,6 +162,8 @@ src/renderers/shared/stack/reconciler/__tests__/ReactComponentLifeCycle-test.js * warns if findDOMNode is used inside render src/renderers/shared/stack/reconciler/__tests__/ReactCompositeComponent-test.js +* should warn about `forceUpdate` on unmounted components +* should warn about `setState` on unmounted components * should disallow nested render calls * should warn when mutated props are passed diff --git a/src/renderers/shared/fiber/ReactFiberScheduler.js b/src/renderers/shared/fiber/ReactFiberScheduler.js index 71aff51a26..f3d7c23a3d 100644 --- a/src/renderers/shared/fiber/ReactFiberScheduler.js +++ b/src/renderers/shared/fiber/ReactFiberScheduler.js @@ -760,7 +760,8 @@ module.exports = function(config : HostConfig) { scheduleWorkAtPriority(root, priorityLevel); return; } else { - throw new Error('Invalid root'); + // TODO: Warn about setting state on an unmounted component. + return; } } fiber = fiber.return; diff --git a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js index d7ea65be32..2a15d71383 100644 --- a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js +++ b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js @@ -678,7 +678,7 @@ var ReactCompositeComponent = { var inst = this._instance; var childContext; - if (inst.getChildContext) { + if (typeof inst.getChildContext === 'function') { if (__DEV__) { ReactInstrumentation.debugTool.onBeginProcessingChildContext(); try { @@ -689,9 +689,7 @@ var ReactCompositeComponent = { } else { childContext = inst.getChildContext(); } - } - if (childContext) { invariant( typeof Component.childContextTypes === 'object', '%s.getChildContext(): childContextTypes must be defined in order to ' + diff --git a/src/renderers/shared/stack/reconciler/__tests__/ReactCompositeComponent-test.js b/src/renderers/shared/stack/reconciler/__tests__/ReactCompositeComponent-test.js index 4fcc514b3b..2698783958 100644 --- a/src/renderers/shared/stack/reconciler/__tests__/ReactCompositeComponent-test.js +++ b/src/renderers/shared/stack/reconciler/__tests__/ReactCompositeComponent-test.js @@ -427,6 +427,7 @@ describe('ReactCompositeComponent', () => { return
; } } + Component.childContextTypes = {}; expectDev(console.error.calls.count()).toBe(0); var instance = ReactDOM.render(, container);