Skip to content

Commit b2fd5f2

Browse files
committed
Allow overlapping rects if the overlapping one is a parent
Meaning a child can still print its title when its parent rect is around it.
1 parent eb9a1b4 commit b2fd5f2

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ function ScaledRect({
7979

8080
function SuspenseRects({
8181
suspenseID,
82+
parentRects,
8283
}: {
8384
suspenseID: SuspenseNode['id'],
85+
parentRects: null | Array<Rect>,
8486
}): React$Node {
8587
const store = useContext(StoreContext);
8688
const treeDispatch = useContext(TreeDispatcherContext);
@@ -175,7 +177,14 @@ function SuspenseRects({
175177
// other rects.
176178
// TODO: This should probably be memoized based on if any changes to the rtree has been made.
177179
const titleBox: null | Rect =
178-
rects === null ? null : findTitleBox(store._rtree, rects);
180+
rects === null ? null : findTitleBox(store._rtree, rects, parentRects);
181+
182+
const nextRects =
183+
rects === null || rects.length === 0
184+
? parentRects
185+
: parentRects === null || parentRects.length === 0
186+
? rects
187+
: parentRects.concat(rects);
179188

180189
return (
181190
<ScaledRect
@@ -213,7 +222,13 @@ function SuspenseRects({
213222
className={styles.SuspenseRectsBoundaryChildren}
214223
rect={boundingBox}>
215224
{suspense.children.map(childID => {
216-
return <SuspenseRects key={childID} suspenseID={childID} />;
225+
return (
226+
<SuspenseRects
227+
key={childID}
228+
suspenseID={childID}
229+
parentRects={nextRects}
230+
/>
231+
);
217232
})}
218233
</ScaledRect>
219234
)}
@@ -333,7 +348,11 @@ function getDocumentBoundingRect(
333348
};
334349
}
335350

336-
function findTitleBox(rtree: RBush<Rect>, rects: Array<Rect>): null | Rect {
351+
function findTitleBox(
352+
rtree: RBush<Rect>,
353+
rects: Array<Rect>,
354+
parentRects: null | Array<Rect>,
355+
): null | Rect {
337356
for (let i = 0; i < rects.length; i++) {
338357
const rect = rects[i];
339358
if (rect.width < 50 || rect.height < 10) {
@@ -369,6 +388,14 @@ function findTitleBox(rtree: RBush<Rect>, rects: Array<Rect>): null | Rect {
369388
const x = overlappingRect.x;
370389
const y = overlappingRect.y;
371390
if (y < maxY && x < maxX) {
391+
if (
392+
parentRects !== null &&
393+
parentRects.indexOf(overlappingRect) !== -1
394+
) {
395+
// This rect overlaps but it's part of a parent boundary. We let
396+
// title content render if it's on top and not a sibling.
397+
continue;
398+
}
372399
// This rect cuts into the remaining space. Let's figure out if we're
373400
// better off cutting on the x or y axis to maximize remaining space.
374401
const remainderX = x - minX;
@@ -401,7 +428,9 @@ function SuspenseRectsRoot({rootID}: {rootID: SuspenseNode['id']}): React$Node {
401428
}
402429

403430
return root.children.map(childID => {
404-
return <SuspenseRects key={childID} suspenseID={childID} />;
431+
return (
432+
<SuspenseRects key={childID} suspenseID={childID} parentRects={null} />
433+
);
405434
});
406435
}
407436

0 commit comments

Comments
 (0)