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). 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.
  • Loading branch information
Brian Vaughn committed Jan 3, 2017
1 parent 7dc5f91 commit de2356f
Show file tree
Hide file tree
Showing 3 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/renderers/dom/__tests__/ReactDOMProduction-test.js
* should throw with an error code in production

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

// Store updated context for prevContext param in next call to componentDidUpdate().
// Use an expando property on instance rather than Fiber because:
// 1) Conditional fields on fibers would break monomorphism.
// 2) Adding to all fibers would bloat types that don't use context.
instance.__reactInternalPrevContext = instance.context;
return;
}
case HostRoot: {
Expand Down

0 comments on commit de2356f

Please sign in to comment.