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

Support inner component _debugOwner in memo #19556

Merged
merged 6 commits into from
Aug 10, 2020
Next Next commit
Support inner component _debugOwner in memo
  • Loading branch information
hanq08 committed Apr 17, 2020
commit 803bdce2ae7b6ab3db306545e38ebb61b12017f6
3 changes: 3 additions & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ function updateMemoComponent(
child.ref = workInProgress.ref;
child.return = workInProgress;
workInProgress.child = child;
if (__DEV__) {
child._debugOwner = workInProgress;
}
return child;
}
if (__DEV__) {
Expand Down
16 changes: 16 additions & 0 deletions packages/react-reconciler/src/__tests__/ReactMemo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,5 +497,21 @@ describe('memo', () => {
expect(root).toMatchRenderedOutput('1');
});
});

it('inner component of react memo should have _debugOwner set', async () => {
const InComponent = React.forwardRef((props, ref) => <div ref={ref} />);
const Outer = React.memo(InComponent);
const App = () => {
const ref = React.createRef();
return <Outer ref={ref}>Click me! </Outer>;
};
ReactNoop.render(<App />);
expect(Scheduler).toFlushWithoutYielding();
const innerFiber = ReactNoop.getRoot().current.child.child.child;
const innerFiberOwner = innerFiber._debugOwner;
expect(innerFiber.type.$$typeof).toBe(Symbol.for('react.forward_ref'));
expect(innerFiberOwner).not.toBeNull();
expect(innerFiberOwner.type.$$typeof).toBe(Symbol.for('react.memo'));
});
}
});