Skip to content

Commit d9aea00

Browse files
author
Brian Vaughn
committed
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.
1 parent c978f78 commit d9aea00

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

scripts/fiber/tests-failing.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ src/addons/__tests__/ReactFragment-test.js
66
* should throw if a plain object even if it is in an owner
77
* should throw if a plain object looks like an old element
88

9-
src/isomorphic/classic/__tests__/ReactContextValidator-test.js
10-
* should pass previous context to lifecycles
11-
129
src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js
1310
* includes the owner name when passing null, undefined, boolean, or number
1411

scripts/fiber/tests-passing.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ src/isomorphic/children/__tests__/sliceChildren-test.js
153153
src/isomorphic/classic/__tests__/ReactContextValidator-test.js
154154
* should filter out context not in contextTypes
155155
* should pass next context to lifecycles
156+
* should pass previous context to lifecycles
156157
* should check context types
157158
* should check child context types
158159

src/renderers/shared/fiber/ReactFiberCommitWork.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ module.exports = function<T, P, I, TI, C, CX>(
412412
if (typeof instance.componentDidUpdate === 'function') {
413413
const prevProps = current.memoizedProps;
414414
const prevState = current.memoizedState;
415-
instance.componentDidUpdate(prevProps, prevState);
415+
const prevContext = instance.__reactInternalPrevContext;
416+
instance.componentDidUpdate(prevProps, prevState, prevContext);
416417
}
417418
}
418419
attachRef(current, finishedWork, instance);

src/renderers/shared/fiber/ReactFiberScheduler.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
289289
// Use Task priority for lifecycle updates
290290
if (nextEffect.effectTag & (Update | Callback)) {
291291
commitLifeCycles(current, nextEffect);
292+
293+
// Store updated context for subsequent calls to componentDidUpdate().
294+
nextEffect.stateNode.__reactInternalPrevContext = nextEffect.stateNode.context;
292295
}
293296

294297
if (nextEffect.effectTag & Err) {

0 commit comments

Comments
 (0)