@@ -79,10 +79,11 @@ export function getImperativePanelMethods({
7979 /**
8080 * Compute the next (unvalidated) layout when resizing a panel imperatively.
8181 *
82- * Handles the edge case where the last panel is being collapsed but all
83- * preceding panels are already collapsed — the normal reversed-delta logic
84- * would cascade the freed space to the first panel. Instead the last panel
85- * keeps the remainder so it stays the largest.
82+ * Handles two edge cases for the last panel:
83+ * 1. Single panel in the group — no sibling exists to form valid pivot indices.
84+ * 2. All preceding panels are already collapsed — the normal reversed-delta
85+ * logic would cascade the freed space to the first panel. Instead the last
86+ * panel keeps the remainder so it stays the largest.
8687 */
8788 const computeLayout = ( {
8889 nextSize,
@@ -98,20 +99,22 @@ export function getImperativePanelMethods({
9899 const prevSize = getPanelSize ( ) ;
99100
100101 const index = panels . findIndex ( ( current ) => current . id === panelId ) ;
102+ const isFirstPanel = index === 0 ;
101103 const isLastPanel = index === panels . length - 1 ;
102104
103- if (
105+ const allPreviousCollapsed =
104106 isLastPanel &&
105107 nextSize < prevSize &&
106- index > 0 &&
107- panels . slice ( 0 , index ) . every ( ( _panel , panelIndex ) => {
108- const pc = derivedPanelConstraints [ panelIndex ] ;
109- return (
110- pc ?. collapsible &&
111- layoutNumbersEqual ( pc . collapsedSize , prevLayout [ pc . panelId ] )
112- ) ;
113- } )
114- ) {
108+ ( isFirstPanel ||
109+ panels . slice ( 0 , index ) . every ( ( _panel , panelIndex ) => {
110+ const pc = derivedPanelConstraints [ panelIndex ] ;
111+ return (
112+ pc ?. collapsible &&
113+ layoutNumbersEqual ( pc . collapsedSize , prevLayout [ pc . panelId ] )
114+ ) ;
115+ } ) ) ;
116+
117+ if ( allPreviousCollapsed ) {
115118 const occupiedByPrevious = panels
116119 . slice ( 0 , index )
117120 . reduce ( ( total , panel ) => total + prevLayout [ panel . id ] , 0 ) ;
0 commit comments