Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ Array [
]
`;

exports[`OwnersListContext should include all owners for a component wrapped in react memo : owners for "Anonymous" 1`] = `
Array [
Object {
"displayName": "Grandparent",
"hocDisplayNames": null,
"id": 2,
"type": 5,
},
Object {
"displayName": "Anonymous",
"hocDisplayNames": null,
"id": 3,
"type": 8,
},
Object {
"displayName": "Anonymous",
"hocDisplayNames": null,
"id": 4,
"type": 6,
},
]
`;

Copy link
Contributor

Choose a reason for hiding this comment

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

This snapshot is out of date now. (Not your fault.) Rebasing on master would result in a snapshot delta of:

diff --git a/packages/react-devtools-shared/src/__tests__/__snapshots__/ownersListContext-test.js.snap b/packages/react-devtools-shared/src/__tests__/__snapshots__/ownersListContext-test.js.snap
index 7ef006fda..9b7609788 100644
--- a/packages/react-devtools-shared/src/__tests__/__snapshots__/ownersListContext-test.js.snap
+++ b/packages/react-devtools-shared/src/__tests__/__snapshots__/ownersListContext-test.js.snap
@@ -88,13 +88,17 @@ Array [
   },
   Object {
     "displayName": "Anonymous",
-    "hocDisplayNames": null,
+    "hocDisplayNames": Array [
+      "Memo",
+    ],
     "id": 3,
     "type": 8,
   },
   Object {
     "displayName": "Anonymous",
-    "hocDisplayNames": null,
+    "hocDisplayNames": Array [
+      "ForwardRef",
+    ],
     "id": 4,
     "type": 6,
   },

exports[`OwnersListContext should include the current element even if there are no other owners: mount 1`] = `
[root]
<Grandparent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,42 @@ describe('OwnersListContext', () => {

done();
});

it('should include all owners for a component wrapped in react memo ', async done => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
it('should include all owners for a component wrapped in react memo ', async done => {
it('should include all owners for a component wrapped in react memo', async done => {

const InnerComponent = React.forwardRef((props, ref) => <div ref={ref} />);
const Memo = React.memo(InnerComponent);
const Grandparent = () => {
const ref = React.createRef();
return <Memo ref={ref} />;
};
Comment on lines +211 to +216
Copy link
Contributor

Choose a reason for hiding this comment

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

nit Let's use a named function so we don't see "Anonymous" in the tests?

Suggested change
const InnerComponent = React.forwardRef((props, ref) => <div ref={ref} />);
const Memo = React.memo(InnerComponent);
const Grandparent = () => {
const ref = React.createRef();
return <Memo ref={ref} />;
};
const InnerComponent = (props, ref) => <div ref={ref} />;
const ForwardRef = React.forwardRef(InnerComponent);
const Memo = React.memo(ForwardRef);
const Grandparent = () => {
const ref = React.createRef();
return <Memo ref={ref} />;
};


utils.act(() =>
ReactDOM.render(<Grandparent />, document.createElement('div')),
);

let didFinish = false;
function Suspender({owner}) {
const read = React.useContext(OwnersListContext);
const owners = read(owner.id);
didFinish = true;
expect(owners.length).toBe(3);
expect(owners).toMatchSnapshot(
`owners for "${(owner && owner.displayName) || ''}"`,
);
return null;
}

const wrapped = ((store.getElementAtIndex(2): any): Element);
await utils.actAsync(() =>
TestRenderer.create(
<Contexts defaultOwnerID={wrapped.id}>
<React.Suspense fallback={null}>
<Suspender owner={wrapped} />
</React.Suspense>
</Contexts>,
),
);
expect(didFinish).toBe(true);
done();
});
});
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
3 changes: 3 additions & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.old.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