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 22, 2016
1 parent c978f78 commit ec855f5
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
Original file line number Diff line number Diff line change
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/isomorphic/classic/element/__tests__/ReactElementValidator-test.js
* includes the owner name when passing null, undefined, boolean, or number

Expand Down
1 change: 1 addition & 0 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,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
Original file line number Diff line number Diff line change
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 alls to componentDidUpdate().
nextEffect.stateNode.__reactInternalPrevContext = nextEffect.stateNode.context;
}

if (nextEffect.effectTag & Err) {
Expand Down

0 comments on commit ec855f5

Please sign in to comment.