Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize props memoization #13900

Merged
merged 2 commits into from Oct 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 2 additions & 35 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Expand Up @@ -230,7 +230,6 @@ function updateForwardRef(
nextChildren,
renderExpirationTime,
);
memoizeProps(workInProgress, nextProps);
return workInProgress.child;
}

Expand Down Expand Up @@ -282,7 +281,6 @@ function updatePureComponent(
nextChildren,
renderExpirationTime,
);
memoizeProps(workInProgress, nextProps);
return workInProgress.child;
}

Expand All @@ -298,7 +296,6 @@ function updateFragment(
nextChildren,
renderExpirationTime,
);
memoizeProps(workInProgress, nextChildren);
return workInProgress.child;
}

Expand All @@ -314,7 +311,6 @@ function updateMode(
nextChildren,
renderExpirationTime,
);
memoizeProps(workInProgress, nextChildren);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is interesting because it doesn't memoize its props. Only its children. This is a bug since it won't bail out ever.

return workInProgress.child;
}

Expand All @@ -334,7 +330,6 @@ function updateProfiler(
nextChildren,
renderExpirationTime,
);
memoizeProps(workInProgress, nextProps);
return workInProgress.child;
}

Expand Down Expand Up @@ -378,7 +373,6 @@ function updateFunctionComponent(
nextChildren,
renderExpirationTime,
);
memoizeProps(workInProgress, nextProps);
return workInProgress.child;
}

Expand Down Expand Up @@ -530,10 +524,9 @@ function finishClassComponent(
);
}

// Memoize props and state using the values we just used to render.
// Memoize state using the values we just used to render.
// TODO: Restructure so we never read values from the instance.
memoizeState(workInProgress, instance.state);
memoizeProps(workInProgress, instance.props);
workInProgress.memoizedState = instance.state;

// The context might have changed so we need to recalculate it.
if (hasContext) {
Expand Down Expand Up @@ -667,7 +660,6 @@ function updateHostComponent(current, workInProgress, renderExpirationTime) {
) {
// Schedule this fiber to re-render at offscreen priority. Then bailout.
workInProgress.expirationTime = Never;
workInProgress.memoizedProps = nextProps;
return null;
}

Expand All @@ -677,16 +669,13 @@ function updateHostComponent(current, workInProgress, renderExpirationTime) {
nextChildren,
renderExpirationTime,
);
memoizeProps(workInProgress, nextProps);
return workInProgress.child;
}

function updateHostText(current, workInProgress) {
if (current === null) {
tryToClaimNextHydratableInstance(workInProgress);
}
const nextProps = workInProgress.pendingProps;
memoizeProps(workInProgress, nextProps);
// Nothing to do here. This is terminal. We'll do the completion step
// immediately after.
return null;
Expand Down Expand Up @@ -796,7 +785,6 @@ function mountIndeterminateComponent(
);
}
}
workInProgress.memoizedProps = props;
return child;
}

Expand Down Expand Up @@ -945,7 +933,6 @@ function mountIndeterminateComponent(
}
}
reconcileChildren(null, workInProgress, value, renderExpirationTime);
memoizeProps(workInProgress, props);
return workInProgress.child;
}
}
Expand Down Expand Up @@ -1156,7 +1143,6 @@ function updateSuspenseComponent(
}
}

workInProgress.memoizedProps = nextProps;
workInProgress.memoizedState = nextState;
workInProgress.child = child;
return next;
Expand All @@ -1181,15 +1167,13 @@ function updatePortalComponent(
nextChildren,
renderExpirationTime,
);
memoizeProps(workInProgress, nextChildren);
} else {
reconcileChildren(
current,
workInProgress,
nextChildren,
renderExpirationTime,
);
memoizeProps(workInProgress, nextChildren);
}
return workInProgress.child;
}
Expand All @@ -1206,7 +1190,6 @@ function updateContextProvider(
const oldProps = workInProgress.memoizedProps;

const newValue = newProps.value;
workInProgress.memoizedProps = newProps;

if (__DEV__) {
const providerPropTypes = workInProgress.type.propTypes;
Expand Down Expand Up @@ -1318,7 +1301,6 @@ function updateContextConsumer(
// React DevTools reads this flag.
workInProgress.effectTag |= PerformedWork;
reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
workInProgress.memoizedProps = newProps;
return workInProgress.child;
}

Expand Down Expand Up @@ -1376,17 +1358,6 @@ function bailoutOnAlreadyFinishedWork(
}
}

// TODO: Delete memoizeProps/State and move to reconcile/bailout instead
function memoizeProps(workInProgress: Fiber, nextProps: any) {
workInProgress.memoizedProps = nextProps;
}

function memoizeState(workInProgress: Fiber, nextState: any) {
workInProgress.memoizedState = nextState;
// Don't reset the updateQueue, in case there are pending updates. Resetting
// is handled by processUpdateQueue.
}

function beginWork(
current: Fiber | null,
workInProgress: Fiber,
Expand Down Expand Up @@ -1508,7 +1479,6 @@ function beginWork(
resolveDefaultProps(Component, unresolvedProps),
renderExpirationTime,
);
workInProgress.memoizedProps = unresolvedProps;
return child;
}
case ClassComponent: {
Expand All @@ -1533,7 +1503,6 @@ function beginWork(
resolveDefaultProps(Component, unresolvedProps),
renderExpirationTime,
);
workInProgress.memoizedProps = unresolvedProps;
return child;
}
case HostRoot:
Expand Down Expand Up @@ -1575,7 +1544,6 @@ function beginWork(
resolveDefaultProps(Component, unresolvedProps),
renderExpirationTime,
);
workInProgress.memoizedProps = unresolvedProps;
return child;
}
case Fragment:
Expand Down Expand Up @@ -1619,7 +1587,6 @@ function beginWork(
updateExpirationTime,
renderExpirationTime,
);
workInProgress.memoizedProps = unresolvedProps;
return child;
}
default:
Expand Down
2 changes: 2 additions & 0 deletions packages/react-reconciler/src/ReactFiberScheduler.js
Expand Up @@ -1086,13 +1086,15 @@ function performUnitOfWork(workInProgress: Fiber): Fiber | null {
}

next = beginWork(current, workInProgress, nextRenderExpirationTime);
workInProgress.memoizedProps = workInProgress.pendingProps;

if (workInProgress.mode & ProfileMode) {
// Record the render duration assuming we didn't bailout (or error).
stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
}
} else {
next = beginWork(current, workInProgress, nextRenderExpirationTime);
workInProgress.memoizedProps = workInProgress.pendingProps;
}

if (__DEV__) {
Expand Down