GeezerVison is showing github.com — Support inner component _debugOwner in memo (#19556) · react/react@0c52e24
File treeExpand file treeCollapse file tree Open diff view settings react-devtools-shared/src/__tests__
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/__tests__/__snapshots__/ownersListContext-test.js.snap +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -78,6 +78,33 @@ Array [ | 78 | 78 | ] | 79 | 79 | `; | 80 | 80 |
| | 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 | +
| 81 | 108 | exports[`OwnersListContext should include the current element even if there are no other owners: mount 1`] = ` | 82 | 109 | [root] | 83 | 110 | <Grandparent> | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/__tests__/ownersListContext-test.js +39Lines changed: 39 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -206,4 +206,43 @@ describe('OwnersListContext', () => { | 206 | 206 |
| 207 | 207 | done(); | 208 | 208 | }); | | 209 | + | | 210 | + it('should include all owners for a component wrapped in react memo', async done => { | | 211 | + const InnerComponent = (props, ref) => <div ref={ref} />; | | 212 | + const ForwardRef = React.forwardRef(InnerComponent); | | 213 | + const Memo = React.memo(ForwardRef); | | 214 | + const Grandparent = () => { | | 215 | + const ref = React.createRef(); | | 216 | + return <Memo ref={ref} />; | | 217 | + }; | | 218 | + | | 219 | + utils.act(() => | | 220 | + ReactDOM.render(<Grandparent />, document.createElement('div')), | | 221 | + ); | | 222 | + | | 223 | + let didFinish = false; | | 224 | + function Suspender({owner}) { | | 225 | + const read = React.useContext(OwnersListContext); | | 226 | + const owners = read(owner.id); | | 227 | + didFinish = true; | | 228 | + expect(owners.length).toBe(3); | | 229 | + expect(owners).toMatchSnapshot( | | 230 | + `owners for "${(owner && owner.displayName) || ''}"`, | | 231 | + ); | | 232 | + return null; | | 233 | + } | | 234 | + | | 235 | + const wrapped = ((store.getElementAtIndex(2): any): Element); | | 236 | + await utils.actAsync(() => | | 237 | + TestRenderer.create( | | 238 | + <Contexts defaultOwnerID={wrapped.id}> | | 239 | + <React.Suspense fallback={null}> | | 240 | + <Suspender owner={wrapped} /> | | 241 | + </React.Suspense> | | 242 | + </Contexts>, | | 243 | + ), | | 244 | + ); | | 245 | + expect(didFinish).toBe(true); | | 246 | + done(); | | 247 | + }); | 209 | 248 | }); |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiber.new.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -579,6 +579,10 @@ export function createFiberFromTypeAndProps( | 579 | 579 | fiber.type = resolvedType; | 580 | 580 | fiber.lanes = lanes; | 581 | 581 |
| | 582 | + if (__DEV__) { | | 583 | + fiber._debugOwner = owner; | | 584 | + } | | 585 | + | 582 | 586 | return fiber; | 583 | 587 | } | 584 | 588 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiber.old.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -573,6 +573,10 @@ export function createFiberFromTypeAndProps( | 573 | 573 | fiber.type = resolvedType; | 574 | 574 | fiber.lanes = lanes; | 575 | 575 |
| | 576 | + if (__DEV__) { | | 577 | + fiber._debugOwner = owner; | | 578 | + } | | 579 | + | 576 | 580 | return fiber; | 577 | 581 | } | 578 | 582 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberBeginWork.new.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -434,7 +434,7 @@ function updateMemoComponent( | 434 | 434 | Component.type, | 435 | 435 | null, | 436 | 436 | nextProps, | 437 | | - null, | | 437 | + workInProgress, | 438 | 438 | workInProgress.mode, | 439 | 439 | renderLanes, | 440 | 440 | ); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberBeginWork.old.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -434,7 +434,7 @@ function updateMemoComponent( | 434 | 434 | Component.type, | 435 | 435 | null, | 436 | 436 | nextProps, | 437 | | - null, | | 437 | + workInProgress, | 438 | 438 | workInProgress.mode, | 439 | 439 | renderLanes, | 440 | 440 | ); | |
|