Skip to content

Commit 423c44b

Browse files
authored
[DevTools] Don't highlight the root rect if no roots has unique suspenders (#34885)
Stacked on #34881. We don't paint suspense boundaries if there are no suspenders. This does the same with the root. The root is still selectable so you can confirm but there's no affordance drawing attention to click the root. This could happen if you don't use the built-ins of React to load things like scripts and css. It would never happen in something like Next.js where code and CSS is loaded through React-native like RSC. However, it could also happen in the Activity scoped case when all resources are always loaded early.
1 parent f970d5f commit 423c44b

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
.SuspenseRectsContainer {
22
padding: .25rem;
3-
cursor: pointer;
4-
outline-color: var(--color-transition);
3+
outline-color: transparent;
54
outline-style: solid;
65
outline-width: 1px;
76
border-radius: 0.25rem;
8-
background-color: color-mix(in srgb, var(--color-transition) 5%, transparent);
9-
}
10-
11-
.SuspenseRectsContainer[data-hovered='true'] {
12-
background-color: color-mix(in srgb, var(--color-transition) 15%, transparent);
137
}
148

159
.SuspenseRectsContainer[data-highlighted='true'] {
10+
outline-color: var(--color-transition);
1611
outline-style: solid;
1712
outline-width: 4px;
1813
}
1914

15+
.SuspenseRectsRoot {
16+
cursor: pointer;
17+
outline-color: var(--color-transition);
18+
background-color: color-mix(in srgb, var(--color-transition) 5%, transparent);
19+
}
20+
21+
.SuspenseRectsRoot[data-hovered='true'] {
22+
background-color: color-mix(in srgb, var(--color-transition) 15%, transparent);
23+
}
24+
2025
.SuspenseRectsViewBox {
2126
position: relative;
2227
}

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ function SuspenseRectsContainer(): React$Node {
326326
const treeDispatch = useContext(TreeDispatcherContext);
327327
const suspenseTreeDispatch = useContext(SuspenseTreeDispatcherContext);
328328
// TODO: This relies on a full re-render of all children when the Suspense tree changes.
329-
const {roots, hoveredTimelineIndex} = useContext(SuspenseTreeStateContext);
329+
const {roots, hoveredTimelineIndex, uniqueSuspendersOnly} = useContext(
330+
SuspenseTreeStateContext,
331+
);
330332

331333
// TODO: bbox does not consider uniqueSuspendersOnly filter
332334
const boundingBox = getDocumentBoundingRect(store, roots);
@@ -372,9 +374,26 @@ function SuspenseRectsContainer(): React$Node {
372374
const isRootSelected = roots.includes(inspectedElementID);
373375
const isRootHovered = hoveredTimelineIndex === 0;
374376

377+
let hasRootSuspenders = false;
378+
if (!uniqueSuspendersOnly) {
379+
hasRootSuspenders = true;
380+
} else {
381+
for (let i = 0; i < roots.length; i++) {
382+
const rootID = roots[i];
383+
const root = store.getSuspenseByID(rootID);
384+
if (root !== null && root.hasUniqueSuspenders) {
385+
hasRootSuspenders = true;
386+
break;
387+
}
388+
}
389+
}
390+
375391
return (
376392
<div
377-
className={styles.SuspenseRectsContainer}
393+
className={
394+
styles.SuspenseRectsContainer +
395+
(hasRootSuspenders ? ' ' + styles.SuspenseRectsRoot : '')
396+
}
378397
onClick={handleClick}
379398
onDoubleClick={handleDoubleClick}
380399
data-highlighted={isRootSelected}

0 commit comments

Comments
 (0)