Skip to content

Commit 0c52e24

Browse files
Brian Vaughnhanq08
Brian Vaughn
andauthored
Support inner component _debugOwner in memo (#19556)
* Support inner component _debugOwner in memo * test with devtool context * remove memo test * Merged master; tweaked test and snapshot * Pass owner to createFiber fn when creating a memo component. Co-authored-by: Theodore Han <tqhan317@gmail.com>
1 parent 94c0244 commit 0c52e24

File tree

6 files changed

+76
-2
lines changed

6 files changed

+76
-2
lines changed

packages/react-devtools-shared/src/__tests__/__snapshots__/ownersListContext-test.js.snap

+27
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,33 @@ Array [
7878
]
7979
`;
8080
81+
exports[`OwnersListContext should include all owners for a component wrapped in react memo: owners for "InnerComponent" 1`] = `
82+
Array [
83+
Object {
84+
"displayName": "Grandparent",
85+
"hocDisplayNames": null,
86+
"id": 2,
87+
"type": 5,
88+
},
89+
Object {
90+
"displayName": "InnerComponent",
91+
"hocDisplayNames": Array [
92+
"Memo",
93+
],
94+
"id": 3,
95+
"type": 8,
96+
},
97+
Object {
98+
"displayName": "InnerComponent",
99+
"hocDisplayNames": Array [
100+
"ForwardRef",
101+
],
102+
"id": 4,
103+
"type": 6,
104+
},
105+
]
106+
`;
107+
81108
exports[`OwnersListContext should include the current element even if there are no other owners: mount 1`] = `
82109
[root]
83110
<Grandparent>

packages/react-devtools-shared/src/__tests__/ownersListContext-test.js

+39
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,43 @@ describe('OwnersListContext', () => {
206206

207207
done();
208208
});
209+
210+
it('should include all owners for a component wrapped in react memo',asyncdone=>{
211+
constInnerComponent=(props,ref)=><divref={ref}/>;
212+
constForwardRef=React.forwardRef(InnerComponent);
213+
constMemo=React.memo(ForwardRef);
214+
constGrandparent=()=>{
215+
constref=React.createRef();
216+
return<Memoref={ref}/>;
217+
};
218+
219+
utils.act(()=>
220+
ReactDOM.render(<Grandparent/>,document.createElement('div')),
221+
);
222+
223+
letdidFinish=false;
224+
functionSuspender({owner}){
225+
constread=React.useContext(OwnersListContext);
226+
constowners=read(owner.id);
227+
didFinish=true;
228+
expect(owners.length).toBe(3);
229+
expect(owners).toMatchSnapshot(
230+
`owners for "${(owner&&owner.displayName)||''}"`,
231+
);
232+
returnnull;
233+
}
234+
235+
constwrapped=((store.getElementAtIndex(2): any): Element);
236+
awaitutils.actAsync(()=>
237+
TestRenderer.create(
238+
<ContextsdefaultOwnerID={wrapped.id}>
239+
<React.Suspensefallback={null}>
240+
<Suspenderowner={wrapped}/>
241+
</React.Suspense>
242+
</Contexts>,
243+
),
244+
);
245+
expect(didFinish).toBe(true);
246+
done();
247+
});
209248
});

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

+4
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,10 @@ export function createFiberFromTypeAndProps(
579579
fiber.type=resolvedType;
580580
fiber.lanes=lanes;
581581

582+
if(__DEV__){
583+
fiber._debugOwner=owner;
584+
}
585+
582586
returnfiber;
583587
}
584588

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

+4
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,10 @@ export function createFiberFromTypeAndProps(
573573
fiber.type=resolvedType;
574574
fiber.lanes=lanes;
575575

576+
if(__DEV__){
577+
fiber._debugOwner=owner;
578+
}
579+
576580
returnfiber;
577581
}
578582

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ function updateMemoComponent(
434434
Component.type,
435435
null,
436436
nextProps,
437-
null,
437+
workInProgress,
438438
workInProgress.mode,
439439
renderLanes,
440440
);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ function updateMemoComponent(
434434
Component.type,
435435
null,
436436
nextProps,
437-
null,
437+
workInProgress,
438438
workInProgress.mode,
439439
renderLanes,
440440
);

0 commit comments

Comments
 (0)
close