Skip to content

Commit 0c68f9d

Browse files
committed
[DevTools] Use same Suspense naming heuristics when reconnecting
1 parent 525d8c9 commit 0c68f9d

File tree

6 files changed

+8
-17
lines changed

6 files changed

+8
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3297,7 +3297,7 @@ describe('Store', () => {
32973297
<Suspense>
32983298
[suspense-root] rects={[{x:1,y:2,width:6,height:1}, {x:1,y:2,width:6,height:1}]}
32993299
<Suspense name="Outer" rects={[{x:1,y:2,width:6,height:1}, {x:1,y:2,width:6,height:1}]}>
3300-
<Suspense name="Unknown" rects={[{x:1,y:2,width:6,height:1}]}>
3300+
<Suspense name="Inner" rects={[{x:1,y:2,width:6,height:1}]}>
33013301
`);
33023302
});
33033303
});

packages/react-devtools-shared/src/backend/fiber/renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2664,7 +2664,7 @@ export function attach(
26642664
26652665
const fiber = fiberInstance.data;
26662666
const props = fiber.memoizedProps;
2667-
// TODO: Compute a fallback name based on Owner, key etc.
2667+
// The frontend will guess a name based on heuristics (e.g. owner) if no explicit name is given.
26682668
const name =
26692669
fiber.tag !== SuspenseComponent || props === null
26702670
? null

packages/react-devtools-shared/src/devtools/store.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,10 +1615,6 @@ export default class Store extends EventEmitter<{
16151615
parentSuspense.children.push(id);
16161616
}
16171617

1618-
if (name === null) {
1619-
name = 'Unknown';
1620-
}
1621-
16221618
this._idToSuspense.set(id, {
16231619
id,
16241620
parentID,
@@ -2135,13 +2131,12 @@ export default class Store extends EventEmitter<{
21352131
throw error;
21362132
}
21372133

2138-
_guessSuspenseName(element: Element): string {
2134+
_guessSuspenseName(element: Element): string | null {
21392135
const owner = this._idToElement.get(element.ownerID);
2140-
let name = 'Unknown';
21412136
if (owner !== undefined && owner.displayName !== null) {
2142-
name = owner.displayName;
2137+
return owner.displayName;
21432138
}
21442139

2145-
return name;
2140+
return null;
21462141
}
21472142
}

packages/react-devtools-shared/src/devtools/utils.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ function printRects(rects: SuspenseNode['rects']): string {
6363
}
6464

6565
function printSuspense(suspense: SuspenseNode): string {
66-
let name = '';
67-
if (suspense.name !== null) {
68-
name = ` name="${suspense.name}"`;
69-
}
70-
66+
const name = ` name="${suspense.name || 'Unknown'}"`;
7167
const printedRects = printRects(suspense.rects);
7268

7369
return `<Suspense${name}${printedRects}>`;

packages/react-devtools-shared/src/devtools/views/SuspenseTab/SuspenseBreadcrumbs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export default function SuspenseBreadcrumbs(): React$Node {
7272
className={styles.SuspenseBreadcrumbsButton}
7373
onClick={handleClick.bind(null, id)}
7474
type="button">
75-
{node === null ? 'Unknown' : node.name}
75+
{node === null ? 'Unknown' : node.name || 'Unknown'}
7676
</button>
7777
</li>
7878
);

packages/react-devtools-shared/src/devtools/views/SuspenseTab/SuspenseRects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function SuspenseRects({
169169
onPointerOver={handlePointerOver}
170170
onPointerLeave={handlePointerLeave}
171171
// Reach-UI tooltip will go out of bounds of parent scroll container.
172-
title={suspense.name}
172+
title={suspense.name || 'Unknown'}
173173
/>
174174
);
175175
})}

0 commit comments

Comments
 (0)