Skip to content

Commit

Permalink
Stored memoized context on fiber
Browse files Browse the repository at this point in the history
This enables us to pass the previous context value to componentDidUpdate()
  • Loading branch information
Brian Vaughn committed Dec 22, 2016
1 parent c978f78 commit 518b194
Show file tree
Hide file tree
Showing 5 changed files with 9 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
5 changes: 5 additions & 0 deletions src/renderers/shared/fiber/ReactFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ export type Fiber = {
// The state used to create the output
memoizedState: any,

// The context used to create the output; stored for ClassComponents only
memoizedContext: any,

// Effect
effectTag: TypeOfSideEffect,

Expand Down Expand Up @@ -201,6 +204,7 @@ var createFiber = function(tag : TypeOfWork, key : null | string) : Fiber {
updateQueue: null,
callbackList: null,
memoizedState: null,
memoizedContext: null,

effectTag: NoEffect,
nextEffect: null,
Expand Down Expand Up @@ -280,6 +284,7 @@ exports.cloneFiber = function(fiber : Fiber, priorityLevel : PriorityLevel) : Fi

alt.memoizedProps = fiber.memoizedProps;
alt.memoizedState = fiber.memoizedState;
alt.memoizedContext = fiber.memoizedContext;

if (__DEV__) {
alt._debugID = fiber._debugID;
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 = current.memoizedContext;
instance.componentDidUpdate(prevProps, prevState, prevContext);
}
}
attachRef(current, finishedWork, instance);
Expand Down
1 change: 1 addition & 0 deletions src/renderers/shared/fiber/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ module.exports = function<T, P, I, TI, C, CX>(
const instance = workInProgress.stateNode;
workInProgress.memoizedState = instance.state;
workInProgress.memoizedProps = instance.props;
workInProgress.memoizedContext = instance.context;

return null;
}
Expand Down

0 comments on commit 518b194

Please sign in to comment.