Skip to content

Commit de2356f

Browse files
author
Brian Vaughn
committed
Pass prevContext param to componentDidUpdate
This makes use of an expando property (__reactInternalPrevContext) on the stateNode (instance). A property on the instance was used instead of a Fiber attribute because: 1) Conditional fields on fibers would break monomorphism. 2) Adding to all fibers would bloat types that don't use context.
1 parent 7dc5f91 commit de2356f

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-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/renderers/dom/__tests__/ReactDOMProduction-test.js
1310
* should throw with an error code in production
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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ module.exports = function<T, P, I, TI, C, CX, CI>(
413413
if (typeof instance.componentDidUpdate === 'function') {
414414
const prevProps = current.memoizedProps;
415415
const prevState = current.memoizedState;
416-
instance.componentDidUpdate(prevProps, prevState);
416+
const prevContext = instance.__reactInternalPrevContext;
417+
instance.componentDidUpdate(prevProps, prevState, prevContext);
417418
}
418419
}
419420
attachRef(current, finishedWork, instance);
@@ -422,6 +423,12 @@ module.exports = function<T, P, I, TI, C, CX, CI>(
422423
if (callbackList) {
423424
commitCallbacks(finishedWork, callbackList, instance);
424425
}
426+
427+
// Store updated context for prevContext param in next call to componentDidUpdate().
428+
// Use an expando property on instance rather than Fiber because:
429+
// 1) Conditional fields on fibers would break monomorphism.
430+
// 2) Adding to all fibers would bloat types that don't use context.
431+
instance.__reactInternalPrevContext = instance.context;
425432
return;
426433
}
427434
case HostRoot: {

0 commit comments

Comments
 (0)