Skip to content

Commit

Permalink
Fix conditional layout edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn committed Feb 24, 2024
1 parent 61c06ba commit 8f5de21
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
29 changes: 29 additions & 0 deletions packages/react-resizable-panels/src/PanelGroup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,35 @@ describe("PanelGroup", () => {
expect(rightPanelElement?.getAttribute("data-panel-size")).toBe("40.0");
});

// github.com/bvaughn/react-resizable-panels/issues/303
it("should recalculate layout after panels are changed", () => {
let mostRecentLayout: number[] | null = null;

const onLayout = (layout: number[]) => {
mostRecentLayout = layout;
};

act(() => {
root.render(
<PanelGroup direction="vertical" onLayout={onLayout}>
<Panel id="foo" minSize={30} order={0} />
<PanelResizeHandle />
<Panel id="bar" minSize={70} order={1} />
</PanelGroup>
);
});
expect(mostRecentLayout).toEqual([30, 70]);

act(() => {
root.render(
<PanelGroup direction="vertical" onLayout={onLayout}>
<Panel id="bar" minSize={70} order={0} />
</PanelGroup>
);
});
expect(mostRecentLayout).toEqual([100]);
});

describe("imperative handle API", () => {
it("should report the most recently rendered group id", () => {
const ref = createRef<ImperativePanelGroupHandle>();
Expand Down
8 changes: 4 additions & 4 deletions packages/react-resizable-panels/src/PanelGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,10 +768,10 @@ function PanelGroupWithForwardedRef({
panelData,
layout
);
assert(
prevPanelSize != null,
`Previous panel size not found for panel "${panelData.id}"`
);
if (prevPanelSize == null) {
// It's possible that the panels in this group have changed since the last render
return;
}

if (
prevCollapsible &&
Expand Down

0 comments on commit 8f5de21

Please sign in to comment.