Skip to content

Commit 31b6954

Browse files
committed
[DevTools] Draw rect for React Root in Suspense tab
1 parent c44fbf4 commit 31b6954

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,10 +854,11 @@ export default class Store extends EventEmitter<{
854854
const lineage: Array<SuspenseNode['id']> = [];
855855
let next: null | SuspenseNode = this.getSuspenseByID(suspenseID);
856856
while (next !== null) {
857+
// Include Root to be able to see what suspended the Shell.
858+
lineage.unshift(next.id);
857859
if (next.parentID === 0) {
858860
next = null;
859861
} else {
860-
lineage.unshift(next.id);
861862
next = this.getSuspenseByID(next.parentID);
862863
}
863864
}
@@ -1205,7 +1206,7 @@ export default class Store extends EventEmitter<{
12051206
this._idToElement.set(id, {
12061207
children: [],
12071208
depth: -1,
1208-
displayName: null,
1209+
displayName: 'React Root',
12091210
hocDisplayNames: null,
12101211
id,
12111212
isCollapsed: false, // Never collapse roots; it would hide the entire tree.
@@ -1539,7 +1540,12 @@ export default class Store extends EventEmitter<{
15391540
if (name === null) {
15401541
// The boundary isn't explicitly named.
15411542
// Pick a sensible default.
1542-
name = this._guessSuspenseName(element);
1543+
if (parentID === 0) {
1544+
// For Roots we use their display name.
1545+
name = element.displayName;
1546+
} else {
1547+
name = this._guessSuspenseName(element);
1548+
}
15431549
}
15441550
}
15451551

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,7 @@ function getDocumentBoundingRect(
221221
};
222222
}
223223

224-
function SuspenseRectsShell({
225-
rootID,
226-
}: {
227-
rootID: SuspenseNode['id'],
228-
}): React$Node {
224+
function SuspenseRectsRoot({rootID}: {rootID: SuspenseNode['id']}): React$Node {
229225
const store = useContext(StoreContext);
230226
const root = store.getSuspenseByID(rootID);
231227
if (root === null) {
@@ -254,14 +250,16 @@ function SuspenseRectsContainer(): React$Node {
254250
const width = '100%';
255251
const aspectRatio = `1 / ${heightScale}`;
256252

253+
function handleClick() {}
254+
257255
return (
258-
<div className={styles.SuspenseRectsContainer}>
256+
<div className={styles.SuspenseRectsContainer} onClick={handleClick}>
259257
<ViewBox.Provider value={boundingBox}>
260258
<div
261259
className={styles.SuspenseRectsViewBox}
262260
style={{aspectRatio, width}}>
263261
{roots.map(rootID => {
264-
return <SuspenseRectsShell key={rootID} rootID={rootID} />;
262+
return <SuspenseRectsRoot key={rootID} rootID={rootID} />;
265263
})}
266264
</div>
267265
</ViewBox.Provider>

0 commit comments

Comments
 (0)