Skip to content

Commit 20b2642

Browse files
committed
fix: filter hidden and out-of-flow children from gap detection
- Skip display:none and position:absolute/fixed children in computeChildGaps to prevent spurious gap rects at viewport origin - Also skip zero-sized children as a safety net - Simplify DOMMatrix.rotate() to single-arg form for Z-axis rotation
1 parent 87af2fc commit 20b2642

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

packages/react-grab/src/components/overlay-canvas.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ export const OverlayCanvas: Component<OverlayCanvasProps> = (props) => {
323323

324324
const pattern = context.createPattern(patternCanvas, "repeat");
325325
if (pattern) {
326-
pattern.setTransform(new DOMMatrix().rotate(0, 0, HATCH_ROTATION_DEG));
326+
pattern.setTransform(new DOMMatrix().rotate(HATCH_ROTATION_DEG));
327327
hatchPatternCache.set(color, pattern);
328328
}
329329
return pattern;

packages/react-grab/src/utils/create-box-model-bounds.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface BoxSides {
1111

1212
const GRID_DISPLAYS = new Set(["grid", "inline-grid"]);
1313
const LAYOUT_DISPLAYS = new Set(["flex", "inline-flex", "grid", "inline-grid"]);
14+
const OUT_OF_FLOW_POSITIONS = new Set(["absolute", "fixed"]);
1415

1516
const parseSides = (style: CSSStyleDeclaration, property: string): BoxSides => ({
1617
top: parseFloat(style.getPropertyValue(`${property}-top`)) || 0,
@@ -86,7 +87,18 @@ const computeChildGaps = (
8687
return [];
8788
}
8889

89-
const childRects = Array.from(element.children).map((child) => child.getBoundingClientRect());
90+
const childRects: DOMRect[] = [];
91+
for (const child of element.children) {
92+
const childStyle = window.getComputedStyle(child);
93+
if (childStyle.display === "none" || OUT_OF_FLOW_POSITIONS.has(childStyle.position)) {
94+
continue;
95+
}
96+
const rect = child.getBoundingClientRect();
97+
if (rect.width === 0 && rect.height === 0) continue;
98+
childRects.push(rect);
99+
}
100+
101+
if (childRects.length < 2) return [];
90102

91103
if (GRID_DISPLAYS.has(style.display)) {
92104
return [

0 commit comments

Comments
 (0)