From f69c7004d7a9568ef1829a4e4880603c332c466f Mon Sep 17 00:00:00 2001 From: Rijk van Wel Date: Thu, 22 Jun 2023 16:00:30 +0200 Subject: [PATCH 1/2] fix onResize not called if there is no onLayout For the initial render, if the layout is restored from local storage, the Panel's `onResize` function is only called if the PanelGroup has a `onLayout`. --- .../react-resizable-panels/src/PanelGroup.ts | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/react-resizable-panels/src/PanelGroup.ts b/packages/react-resizable-panels/src/PanelGroup.ts index 974c1ede1..51d307646 100644 --- a/packages/react-resizable-panels/src/PanelGroup.ts +++ b/packages/react-resizable-panels/src/PanelGroup.ts @@ -232,24 +232,22 @@ function PanelGroupWithForwardedRef({ // Notify external code when sizes have changed. useEffect(() => { const { onLayout } = callbacksRef.current!; - if (onLayout) { - const { panels, sizes } = committedValuesRef.current; + const { panels, sizes } = committedValuesRef.current; - // Don't commit layout until all panels have registered and re-rendered with their actual sizes. - if (sizes.length > 0) { - onLayout(sizes); + // Don't commit layout until all panels have registered and re-rendered with their actual sizes. + if (sizes.length > 0) { + onLayout?.(sizes); - const panelIdToLastNotifiedSizeMap = - panelIdToLastNotifiedSizeMapRef.current; + const panelIdToLastNotifiedSizeMap = + panelIdToLastNotifiedSizeMapRef.current; - // When possible, we notify before the next render so that rendering work can be batched together. - // Some cases are difficult to detect though, - // for example– panels that are conditionally rendered can affect the size of neighboring panels. - // In this case, the best we can do is notify on commit. - // The callPanelCallbacks() uses its own memoization to avoid notifying panels twice in these cases. - const panelsArray = panelsMapToSortedArray(panels); - callPanelCallbacks(panelsArray, sizes, panelIdToLastNotifiedSizeMap); - } + // When possible, we notify before the next render so that rendering work can be batched together. + // Some cases are difficult to detect though, + // for example– panels that are conditionally rendered can affect the size of neighboring panels. + // In this case, the best we can do is notify on commit. + // The callPanelCallbacks() uses its own memoization to avoid notifying panels twice in these cases. + const panelsArray = panelsMapToSortedArray(panels); + callPanelCallbacks(panelsArray, sizes, panelIdToLastNotifiedSizeMap); } }, [sizes]); From 3070e54538aed3c125224b00f5e9799c4be6de44 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 23 Jun 2023 23:46:37 -0400 Subject: [PATCH 2/2] Update PanelGroup.ts Formatting --- packages/react-resizable-panels/src/PanelGroup.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/react-resizable-panels/src/PanelGroup.ts b/packages/react-resizable-panels/src/PanelGroup.ts index 51d307646..079350e6c 100644 --- a/packages/react-resizable-panels/src/PanelGroup.ts +++ b/packages/react-resizable-panels/src/PanelGroup.ts @@ -236,7 +236,9 @@ function PanelGroupWithForwardedRef({ // Don't commit layout until all panels have registered and re-rendered with their actual sizes. if (sizes.length > 0) { - onLayout?.(sizes); + if (onLayout) { + onLayout(sizes); + } const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;