Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conditional layout edge case #309

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading