Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
Brian Vaughn committed Dec 28, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent df6ca0e commit d3dbb13
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 0 additions & 3 deletions scripts/fiber/tests-failing.txt
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
@@ -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

6 changes: 5 additions & 1 deletion src/renderers/shared/fiber/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
@@ -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);
@@ -422,6 +423,9 @@ module.exports = function<T, P, I, TI, C, CX>(
if (callbackList) {
commitCallbacks(finishedWork, callbackList, instance);
}

// Store updated context for subsequent calls to componentDidUpdate().
instance.__reactInternalPrevContext = instance.context;
return;
}
case HostRoot: {

0 comments on commit d3dbb13

Please sign in to comment.