diff --git a/scripts/fiber/tests-failing.txt b/scripts/fiber/tests-failing.txt index ebf46e20be2833..f09c52be237012 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/renderers/dom/__tests__/ReactDOMProduction-test.js * should throw with an error code in production diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index c749ed37ab64d7..3dfeb52b47053c 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 429e892e0bef54..586a684bb8103e 100644 --- a/src/renderers/shared/fiber/ReactFiberCommitWork.js +++ b/src/renderers/shared/fiber/ReactFiberCommitWork.js @@ -413,7 +413,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); @@ -422,6 +423,12 @@ module.exports = function( if (callbackList) { commitCallbacks(finishedWork, callbackList, instance); } + + // Store updated context for prevContext param in next call to componentDidUpdate(). + // Use an expando property on instance rather than Fiber because: + // 1) Conditional fields on fibers would break monomorphism. + // 2) Adding to all fibers would bloat types that don't use context. + instance.__reactInternalPrevContext = instance.context; return; } case HostRoot: {