Skip to content

Commit 60daa37

Browse files
committed
Recycle prevProps in simple memo based on the shallowEqual check
1 parent 4607937 commit 60daa37

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.new.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,9 @@ function updateSimpleMemoComponent(
592592
}
593593
if (current !== null) {
594594
const prevProps = current.memoizedProps;
595-
nextProps = shallowEqual(prevProps, nextProps) ? prevProps : nextProps;
595+
workInProgress.pendingProps = nextProps = shallowEqual(prevProps, nextProps)
596+
? prevProps
597+
: nextProps;
596598
if (
597599
prevProps === nextProps &&
598600
current.ref === workInProgress.ref &&

packages/react-reconciler/src/ReactFiberBeginWork.old.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,9 @@ function updateSimpleMemoComponent(
592592
}
593593
if (current !== null) {
594594
const prevProps = current.memoizedProps;
595-
nextProps = shallowEqual(prevProps, nextProps) ? prevProps : nextProps;
595+
workInProgress.pendingProps = nextProps = shallowEqual(prevProps, nextProps)
596+
? prevProps
597+
: nextProps;
596598
if (
597599
prevProps === nextProps &&
598600
current.ref === workInProgress.ref &&

packages/react-reconciler/src/__tests__/ReactMemo-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@ describe('memo', () => {
222222
expect(ReactNoop.getChildren()).toEqual([
223223
span('Inner render count: 1'),
224224
]);
225+
226+
ReactNoop.render(<Parent value={ctxValue++} />);
227+
expect(Scheduler).toFlushAndYield([]);
228+
expect(ReactNoop.getChildren()).toEqual([
229+
span('Inner render count: 1'),
230+
]);
225231
});
226232

227233
it('accepts custom comparison function', async () => {

0 commit comments

Comments
 (0)