From ec855f57df61df8240f27afee03d071042fa3b81 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Thu, 22 Dec 2016 15:13:36 -0800 Subject: [PATCH] Pass prevContext param to componentDidUpdate This makes use of an expando property, __reactInternalPrevContext, on the stateNode (instance). This resolves the fact that we are not currently passing any value at all to componentDidUpdate for that parameter BUT there still exist some underlying problems with previous context in regard to updates that are aborted before commit. --- scripts/fiber/tests-failing.txt | 3 --- scripts/fiber/tests-passing.txt | 1 + src/renderers/shared/fiber/ReactFiberCommitWork.js | 3 ++- src/renderers/shared/fiber/ReactFiberScheduler.js | 3 +++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/fiber/tests-failing.txt b/scripts/fiber/tests-failing.txt index 9a70a61d8faad..e31c3ad8be2dd 100644 --- a/scripts/fiber/tests-failing.txt +++ b/scripts/fiber/tests-failing.txt @@ -6,9 +6,6 @@ src/addons/__tests__/ReactFragment-test.js * should throw if a plain object even if it is in an owner * should throw if a plain object looks like an old element -src/isomorphic/classic/__tests__/ReactContextValidator-test.js -* should pass previous context to lifecycles - src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js * includes the owner name when passing null, undefined, boolean, or number diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index cc1e1ff464889..0dacaf39c2946 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -153,6 +153,7 @@ src/isomorphic/children/__tests__/sliceChildren-test.js src/isomorphic/classic/__tests__/ReactContextValidator-test.js * should filter out context not in contextTypes * should pass next context to lifecycles +* should pass previous context to lifecycles * should check context types * should check child context types diff --git a/src/renderers/shared/fiber/ReactFiberCommitWork.js b/src/renderers/shared/fiber/ReactFiberCommitWork.js index 879fcf2485ee7..5e0faad5edc2b 100644 --- a/src/renderers/shared/fiber/ReactFiberCommitWork.js +++ b/src/renderers/shared/fiber/ReactFiberCommitWork.js @@ -412,7 +412,8 @@ module.exports = function( if (typeof instance.componentDidUpdate === 'function') { const prevProps = current.memoizedProps; const prevState = current.memoizedState; - instance.componentDidUpdate(prevProps, prevState); + const prevContext = instance.__reactInternalPrevContext; + instance.componentDidUpdate(prevProps, prevState, prevContext); } } attachRef(current, finishedWork, instance); diff --git a/src/renderers/shared/fiber/ReactFiberScheduler.js b/src/renderers/shared/fiber/ReactFiberScheduler.js index 5f203409f9e5e..a64b5a7afb924 100644 --- a/src/renderers/shared/fiber/ReactFiberScheduler.js +++ b/src/renderers/shared/fiber/ReactFiberScheduler.js @@ -289,6 +289,9 @@ module.exports = function(config : HostConfig