Skip to content

Commit eef0fcd

Browse files
committed
Support inner component _debugOwner in memo
1 parent a4b1e65 commit eef0fcd

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,9 @@ function updateMemoComponent(
429429
child.ref = workInProgress.ref;
430430
child.return = workInProgress;
431431
workInProgress.child = child;
432+
if (__DEV__) {
433+
child._debugOwner = workInProgress;
434+
}
432435
return child;
433436
}
434437
if (__DEV__) {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,5 +497,21 @@ describe('memo', () => {
497497
expect(root).toMatchRenderedOutput('1');
498498
});
499499
});
500+
501+
it('inner component of react memo should have _debugOwner set', async () => {
502+
const InComponent = React.forwardRef((props, ref) => (<div ref={ref} />));
503+
const Outer = React.memo(InComponent);
504+
const App = () => {
505+
const ref = React.createRef();
506+
return (<Outer ref={ref}>Click me! </Outer>);
507+
}
508+
ReactNoop.render(<App />);
509+
expect(Scheduler).toFlushWithoutYielding();
510+
const innerFiber = ReactNoop.getRoot().current.child.child.child;
511+
const innerFiberOwner = innerFiber._debugOwner;
512+
expect(innerFiber.type.$$typeof).toBe(Symbol.for('react.forward_ref'));
513+
expect(innerFiberOwner).not.toBeNull();
514+
expect(innerFiberOwner.type.$$typeof).toBe(Symbol.for('react.memo'));
515+
})
500516
}
501517
});

0 commit comments

Comments
 (0)