11import type { Layout , RegisteredGroup } from "../components/group/types" ;
22import { assert } from "../utils/assert" ;
3+ import { calculateAvailableGroupSize } from "./dom/calculateAvailableGroupSize" ;
34import { calculateHitRegions } from "./dom/calculateHitRegions" ;
45import { calculatePanelConstraints } from "./dom/calculatePanelConstraints" ;
56import { onGroupPointerLeave } from "./event-handlers/onGroupPointerLeave" ;
@@ -9,6 +10,7 @@ import { onWindowPointerMove } from "./event-handlers/onWindowPointerMove";
910import { onWindowPointerUp } from "./event-handlers/onWindowPointerUp" ;
1011import { update } from "./mutableState" ;
1112import { calculateDefaultLayout } from "./utils/calculateDefaultLayout" ;
13+ import { layoutsEqual } from "./utils/layoutsEqual" ;
1214import { notifyPanelOnResize } from "./utils/notifyPanelOnResize" ;
1315import { 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 (
0 commit comments