Skip to content

Commit dc7ca94

Browse files
committed
Removed need to check checkVisibility()
1 parent 796886e commit dc7ca94

File tree

6 files changed

+34
-56
lines changed

6 files changed

+34
-56
lines changed

integrations/vite/tests/visibility.spec.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,28 @@ test.describe("visibility", () => {
5454
"/e2e/visibility/display/hidden/"
5555
);
5656

57-
await expect(page.getByText('"onLayoutCount": 0')).toBeVisible();
57+
await expect(page.getByText('"onLayoutCount": 1')).toBeVisible();
58+
// Actual layout values are not meaningful since the Group is not visible
5859

5960
await page.getByText("toggle display hidden → visible").click();
6061

61-
await expect(page.getByText('"onLayoutCount": 1')).toBeVisible();
62+
await expect(page.getByText('"onLayoutCount": 2')).toBeVisible();
6263
await expect(page.getByText("id: left")).toContainText("25%");
6364
await expect(page.getByRole("separator")).toBeVisible();
6465
await expect(page.getByText("id: right")).toContainText("75%");
6566

6667
await page.getByText("toggle display visible → hidden").click();
6768

68-
await expect(page.getByText('"onLayoutCount": 1')).toBeVisible();
69+
await expect(page.getByText('"onLayoutCount": 2')).toBeVisible();
70+
// Actual layout values are not meaningful since the Group is not visible
6971

7072
await page.setViewportSize({
7173
width: 500,
7274
height: 500
7375
});
7476
await page.getByText("toggle display hidden → visible").click();
7577

76-
await expect(page.getByText('"onLayoutCount": 2')).toBeVisible();
78+
await expect(page.getByText('"onLayoutCount": 3')).toBeVisible();
7779
await expect(page.getByText("id: left")).toContainText("33%");
7880
await expect(page.getByRole("separator")).toBeVisible();
7981
await expect(page.getByText("id: right")).toContainText("67%");

lib/components/group/Group.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { GroupContext } from "./GroupContext";
1515
import { sortByElementOffset } from "./sortByElementOffset";
1616
import type { GroupProps, Layout, RegisteredGroup } from "./types";
1717
import { useGroupImperativeHandle } from "./useGroupImperativeHandle";
18-
import { useIsVisible } from "./useIsVisible";
1918

2019
/**
2120
* A Group wraps a set of resizable Panel components.
@@ -63,8 +62,6 @@ export function Group({
6362
const [panels, setPanels] = useState<RegisteredPanel[]>([]);
6463
const [separators, setSeparators] = useState<RegisteredSeparator[]>([]);
6564

66-
const isVisible = useIsVisible(element);
67-
6865
const inMemoryLastExpandedPanelSizesRef = useRef<{
6966
[panelIds: string]: number;
7067
}>({});
@@ -107,13 +104,6 @@ export function Group({
107104
return;
108105
}
109106

110-
if (typeof element.checkVisibility === "function") {
111-
if (!element.checkVisibility()) {
112-
// Wait
113-
return;
114-
}
115-
}
116-
117107
const group: RegisteredGroup = {
118108
defaultLayout,
119109
disableCursor: !!disableCursor,
@@ -178,7 +168,6 @@ export function Group({
178168
disabled,
179169
element,
180170
id,
181-
isVisible,
182171
onLayoutChangeStable,
183172
orientation,
184173
panels,
@@ -208,7 +197,6 @@ export function Group({
208197
style={{
209198
...style,
210199
...cssVariables,
211-
contentVisibility: "auto",
212200
display: "flex",
213201
flexDirection: orientation === "horizontal" ? "row" : "column",
214202
flexWrap: "nowrap"

lib/components/group/useIsVisible.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

lib/global/dom/calculatePanelConstraints.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import { formatLayoutNumber } from "../utils/formatLayoutNumber";
55
import { calculateAvailableGroupSize } from "./calculateAvailableGroupSize";
66

77
export function calculatePanelConstraints(group: RegisteredGroup) {
8-
const { element, panels } = group;
8+
const { panels } = group;
99

10-
if (
11-
typeof element.checkVisibility === "function" &&
12-
!element.checkVisibility()
13-
) {
14-
// Can't calculate anything meaningful if we're within an offscreen tree
10+
const groupSize = calculateAvailableGroupSize({ group });
11+
if (groupSize === 0) {
12+
// Can't calculate anything meaningful if the group has a width/height of 0
13+
// (This could indicate that it's within a hidden subtree)
1514
return panels.map((current) => ({
1615
collapsedSize: 0,
1716
collapsible: current.panelConstraints.collapsible === true,
@@ -22,8 +21,6 @@ export function calculatePanelConstraints(group: RegisteredGroup) {
2221
}));
2322
}
2423

25-
const groupSize = calculateAvailableGroupSize({ group });
26-
2724
return panels.map<PanelConstraints>((panel) => {
2825
const { element, panelConstraints } = panel;
2926

lib/global/mountGroup.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Layout, RegisteredGroup } from "../components/group/types";
22
import { assert } from "../utils/assert";
3+
import { calculateAvailableGroupSize } from "./dom/calculateAvailableGroupSize";
34
import { calculateHitRegions } from "./dom/calculateHitRegions";
45
import { calculatePanelConstraints } from "./dom/calculatePanelConstraints";
56
import { onGroupPointerLeave } from "./event-handlers/onGroupPointerLeave";
@@ -9,6 +10,7 @@ import { onWindowPointerMove } from "./event-handlers/onWindowPointerMove";
910
import { onWindowPointerUp } from "./event-handlers/onWindowPointerUp";
1011
import { update } from "./mutableState";
1112
import { calculateDefaultLayout } from "./utils/calculateDefaultLayout";
13+
import { layoutsEqual } from "./utils/layoutsEqual";
1214
import { notifyPanelOnResize } from "./utils/notifyPanelOnResize";
1315
import { validatePanelGroupLayout } from "./utils/validatePanelGroupLayout";
1416

@@ -31,15 +33,14 @@ export function mountGroup(group: RegisteredGroup) {
3133
for (const entry of entries) {
3234
const { borderBoxSize, target } = entry;
3335
if (target === group.element) {
34-
if (
35-
typeof target.checkVisibility === "function" &&
36-
!target.checkVisibility()
37-
) {
38-
// Constraints can't be calculated for groups within a hidden subtree
39-
return;
40-
}
41-
4236
if (isMounted) {
37+
const groupSize = calculateAvailableGroupSize({ group });
38+
if (groupSize === 0) {
39+
// Can't calculate anything meaningful if the group has a width/height of 0
40+
// (This could indicate that it's within a hidden subtree)
41+
return;
42+
}
43+
4344
update((prevState) => {
4445
const match = prevState.mountedGroups.get(group);
4546
if (match) {
@@ -48,12 +49,21 @@ export function mountGroup(group: RegisteredGroup) {
4849
calculatePanelConstraints(group);
4950

5051
// Revalidate layout in case constraints have changed
51-
const prevLayout = match.layout;
52+
const prevLayout = match.defaultLayoutDeferred
53+
? calculateDefaultLayout(nextDerivedPanelConstraints)
54+
: match.layout;
5255
const nextLayout = validatePanelGroupLayout({
5356
layout: prevLayout,
5457
panelConstraints: nextDerivedPanelConstraints
5558
});
5659

60+
if (
61+
!match.defaultLayoutDeferred &&
62+
layoutsEqual(prevLayout, nextLayout)
63+
) {
64+
return prevState;
65+
}
66+
5767
return {
5868
mountedGroups: new Map(prevState.mountedGroups).set(group, {
5969
derivedPanelConstraints: nextDerivedPanelConstraints,
@@ -84,6 +94,8 @@ export function mountGroup(group: RegisteredGroup) {
8494
}
8595
});
8696

97+
const groupSize = calculateAvailableGroupSize({ group });
98+
8799
// Calculate initial layout for the new Panel configuration
88100
const derivedPanelConstraints = calculatePanelConstraints(group);
89101
const panelIdsKey = group.panels.map(({ id }) => id).join(",");
@@ -100,6 +112,7 @@ export function mountGroup(group: RegisteredGroup) {
100112

101113
const nextState = update((prevState) => ({
102114
mountedGroups: new Map(prevState.mountedGroups).set(group, {
115+
defaultLayoutDeferred: groupSize === 0,
103116
derivedPanelConstraints,
104117
layout: defaultLayoutSafe,
105118
separatorToPanels: new Map(

lib/global/mutableState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type SeparatorToPanelsMap = Map<
1818
export type MountedGroupMap = Map<
1919
RegisteredGroup,
2020
{
21+
defaultLayoutDeferred?: boolean | undefined;
2122
derivedPanelConstraints: PanelConstraints[];
2223
layout: Layout;
2324
separatorToPanels: SeparatorToPanelsMap;

0 commit comments

Comments
 (0)