Skip to content

Commit

Permalink
Pass prevContext param to componentDidUpdate
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Brian Vaughn committed Dec 28, 2016
1 parent df6ca0e commit 336b05d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
3 changes: 0 additions & 3 deletions scripts/fiber/tests-failing.txt
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions scripts/fiber/tests-passing.txt
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/renderers/shared/fiber/ReactFiberCommitWork.js
Expand Up @@ -413,7 +413,8 @@ module.exports = function<T, P, I, TI, C, CX>(
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);
Expand Down
3 changes: 3 additions & 0 deletions src/renderers/shared/fiber/ReactFiberScheduler.js
Expand Up @@ -289,6 +289,9 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
// Use Task priority for lifecycle updates
if (nextEffect.effectTag & (Update | Callback)) {
commitLifeCycles(current, nextEffect);

// Store updated context for subsequent calls to componentDidUpdate().
nextEffect.stateNode.__reactInternalPrevContext = nextEffect.stateNode.context;
}

if (nextEffect.effectTag & Err) {
Expand Down

0 comments on commit 336b05d

Please sign in to comment.