Skip to content

Commit

Permalink
Only resolve props if element type differs
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Nov 6, 2018
1 parent b65fac9 commit 0083e4b
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,18 @@ function commitBeforeMutationLifeCycles(
const prevState = current.memoizedState;
startPhaseTimer(finishedWork, 'getSnapshotBeforeUpdate');
const instance = finishedWork.stateNode;
instance.props = resolveDefaultProps(
finishedWork.type,
finishedWork.memoizedProps,
);
instance.props =
finishedWork.elementType === finishedWork.type
? finishedWork.memoizedProps
: resolveDefaultProps(
finishedWork.type,
finishedWork.memoizedProps,
);
instance.state = finishedWork.memoizedState;
const snapshot = instance.getSnapshotBeforeUpdate(
resolveDefaultProps(finishedWork.type, prevProps),
finishedWork.elementType === finishedWork.type
? prevProps
: resolveDefaultProps(finishedWork.type, prevProps),
prevState,
);
if (__DEV__) {
Expand Down Expand Up @@ -349,24 +354,30 @@ function commitLifeCycles(
if (finishedWork.effectTag & Update) {
if (current === null) {
startPhaseTimer(finishedWork, 'componentDidMount');
instance.props = resolveDefaultProps(
finishedWork.type,
finishedWork.memoizedProps,
);
instance.props =
finishedWork.elementType === finishedWork.type
? finishedWork.memoizedProps
: resolveDefaultProps(
finishedWork.type,
finishedWork.memoizedProps,
);
instance.state = finishedWork.memoizedState;
instance.componentDidMount();
stopPhaseTimer();
} else {
const prevProps = resolveDefaultProps(
finishedWork.type,
current.memoizedProps,
);
const prevProps =
finishedWork.elementType === finishedWork.type
? current.memoizedProps
: resolveDefaultProps(finishedWork.type, current.memoizedProps);
const prevState = current.memoizedState;
startPhaseTimer(finishedWork, 'componentDidUpdate');
instance.props = resolveDefaultProps(
finishedWork.type,
finishedWork.memoizedProps,
);
instance.props =
finishedWork.elementType === finishedWork.type
? finishedWork.memoizedProps
: resolveDefaultProps(
finishedWork.type,
finishedWork.memoizedProps,
);
instance.state = finishedWork.memoizedState;
instance.componentDidUpdate(
prevProps,
Expand Down

0 comments on commit 0083e4b

Please sign in to comment.