Skip to content

Commit 7268d97

Browse files
authored
Centralize props memoization (facebook#13900)
* Move memoizedProps to after beginWork remove memoizeProps helper We always call this at the end. This is now enforced to line up since we do the equality check in the beginning of beginWork. So we can't have special cases. * Inline the one caller of memoizeState
1 parent 0fc0446 commit 7268d97

File tree

2 files changed

+4
-35
lines changed

2 files changed

+4
-35
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ function updateForwardRef(
230230
nextChildren,
231231
renderExpirationTime,
232232
);
233-
memoizeProps(workInProgress, nextProps);
234233
return workInProgress.child;
235234
}
236235

@@ -282,7 +281,6 @@ function updatePureComponent(
282281
nextChildren,
283282
renderExpirationTime,
284283
);
285-
memoizeProps(workInProgress, nextProps);
286284
return workInProgress.child;
287285
}
288286

@@ -298,7 +296,6 @@ function updateFragment(
298296
nextChildren,
299297
renderExpirationTime,
300298
);
301-
memoizeProps(workInProgress, nextChildren);
302299
return workInProgress.child;
303300
}
304301

@@ -314,7 +311,6 @@ function updateMode(
314311
nextChildren,
315312
renderExpirationTime,
316313
);
317-
memoizeProps(workInProgress, nextChildren);
318314
return workInProgress.child;
319315
}
320316

@@ -334,7 +330,6 @@ function updateProfiler(
334330
nextChildren,
335331
renderExpirationTime,
336332
);
337-
memoizeProps(workInProgress, nextProps);
338333
return workInProgress.child;
339334
}
340335

@@ -378,7 +373,6 @@ function updateFunctionComponent(
378373
nextChildren,
379374
renderExpirationTime,
380375
);
381-
memoizeProps(workInProgress, nextProps);
382376
return workInProgress.child;
383377
}
384378

@@ -539,10 +533,9 @@ function finishClassComponent(
539533
);
540534
}
541535

542-
// Memoize props and state using the values we just used to render.
536+
// Memoize state using the values we just used to render.
543537
// TODO: Restructure so we never read values from the instance.
544-
memoizeState(workInProgress, instance.state);
545-
memoizeProps(workInProgress, instance.props);
538+
workInProgress.memoizedState = instance.state;
546539

547540
// The context might have changed so we need to recalculate it.
548541
if (hasContext) {
@@ -676,7 +669,6 @@ function updateHostComponent(current, workInProgress, renderExpirationTime) {
676669
) {
677670
// Schedule this fiber to re-render at offscreen priority. Then bailout.
678671
workInProgress.expirationTime = Never;
679-
workInProgress.memoizedProps = nextProps;
680672
return null;
681673
}
682674

@@ -686,16 +678,13 @@ function updateHostComponent(current, workInProgress, renderExpirationTime) {
686678
nextChildren,
687679
renderExpirationTime,
688680
);
689-
memoizeProps(workInProgress, nextProps);
690681
return workInProgress.child;
691682
}
692683

693684
function updateHostText(current, workInProgress) {
694685
if (current === null) {
695686
tryToClaimNextHydratableInstance(workInProgress);
696687
}
697-
const nextProps = workInProgress.pendingProps;
698-
memoizeProps(workInProgress, nextProps);
699688
// Nothing to do here. This is terminal. We'll do the completion step
700689
// immediately after.
701690
return null;
@@ -805,7 +794,6 @@ function mountIndeterminateComponent(
805794
);
806795
}
807796
}
808-
workInProgress.memoizedProps = props;
809797
return child;
810798
}
811799

@@ -954,7 +942,6 @@ function mountIndeterminateComponent(
954942
}
955943
}
956944
reconcileChildren(null, workInProgress, value, renderExpirationTime);
957-
memoizeProps(workInProgress, props);
958945
return workInProgress.child;
959946
}
960947
}
@@ -1165,7 +1152,6 @@ function updateSuspenseComponent(
11651152
}
11661153
}
11671154

1168-
workInProgress.memoizedProps = nextProps;
11691155
workInProgress.memoizedState = nextState;
11701156
workInProgress.child = child;
11711157
return next;
@@ -1190,15 +1176,13 @@ function updatePortalComponent(
11901176
nextChildren,
11911177
renderExpirationTime,
11921178
);
1193-
memoizeProps(workInProgress, nextChildren);
11941179
} else {
11951180
reconcileChildren(
11961181
current,
11971182
workInProgress,
11981183
nextChildren,
11991184
renderExpirationTime,
12001185
);
1201-
memoizeProps(workInProgress, nextChildren);
12021186
}
12031187
return workInProgress.child;
12041188
}
@@ -1215,7 +1199,6 @@ function updateContextProvider(
12151199
const oldProps = workInProgress.memoizedProps;
12161200

12171201
const newValue = newProps.value;
1218-
workInProgress.memoizedProps = newProps;
12191202

12201203
if (__DEV__) {
12211204
const providerPropTypes = workInProgress.type.propTypes;
@@ -1327,7 +1310,6 @@ function updateContextConsumer(
13271310
// React DevTools reads this flag.
13281311
workInProgress.effectTag |= PerformedWork;
13291312
reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
1330-
workInProgress.memoizedProps = newProps;
13311313
return workInProgress.child;
13321314
}
13331315

@@ -1385,17 +1367,6 @@ function bailoutOnAlreadyFinishedWork(
13851367
}
13861368
}
13871369

1388-
// TODO: Delete memoizeProps/State and move to reconcile/bailout instead
1389-
function memoizeProps(workInProgress: Fiber, nextProps: any) {
1390-
workInProgress.memoizedProps = nextProps;
1391-
}
1392-
1393-
function memoizeState(workInProgress: Fiber, nextState: any) {
1394-
workInProgress.memoizedState = nextState;
1395-
// Don't reset the updateQueue, in case there are pending updates. Resetting
1396-
// is handled by processUpdateQueue.
1397-
}
1398-
13991370
function beginWork(
14001371
current: Fiber | null,
14011372
workInProgress: Fiber,
@@ -1517,7 +1488,6 @@ function beginWork(
15171488
resolveDefaultProps(Component, unresolvedProps),
15181489
renderExpirationTime,
15191490
);
1520-
workInProgress.memoizedProps = unresolvedProps;
15211491
return child;
15221492
}
15231493
case ClassComponent: {
@@ -1542,7 +1512,6 @@ function beginWork(
15421512
resolveDefaultProps(Component, unresolvedProps),
15431513
renderExpirationTime,
15441514
);
1545-
workInProgress.memoizedProps = unresolvedProps;
15461515
return child;
15471516
}
15481517
case HostRoot:
@@ -1584,7 +1553,6 @@ function beginWork(
15841553
resolveDefaultProps(Component, unresolvedProps),
15851554
renderExpirationTime,
15861555
);
1587-
workInProgress.memoizedProps = unresolvedProps;
15881556
return child;
15891557
}
15901558
case Fragment:
@@ -1628,7 +1596,6 @@ function beginWork(
16281596
updateExpirationTime,
16291597
renderExpirationTime,
16301598
);
1631-
workInProgress.memoizedProps = unresolvedProps;
16321599
return child;
16331600
}
16341601
default:

packages/react-reconciler/src/ReactFiberScheduler.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,13 +1091,15 @@ function performUnitOfWork(workInProgress: Fiber): Fiber | null {
10911091
}
10921092

10931093
next = beginWork(current, workInProgress, nextRenderExpirationTime);
1094+
workInProgress.memoizedProps = workInProgress.pendingProps;
10941095

10951096
if (workInProgress.mode & ProfileMode) {
10961097
// Record the render duration assuming we didn't bailout (or error).
10971098
stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
10981099
}
10991100
} else {
11001101
next = beginWork(current, workInProgress, nextRenderExpirationTime);
1102+
workInProgress.memoizedProps = workInProgress.pendingProps;
11011103
}
11021104

11031105
if (__DEV__) {

0 commit comments

Comments
 (0)