diff --git a/packages/react-resizable-panels/src/PanelGroup.test.tsx b/packages/react-resizable-panels/src/PanelGroup.test.tsx
index c6f747af8..abb12ce40 100644
--- a/packages/react-resizable-panels/src/PanelGroup.test.tsx
+++ b/packages/react-resizable-panels/src/PanelGroup.test.tsx
@@ -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(
+
+
+
+
+
+ );
+ });
+ expect(mostRecentLayout).toEqual([30, 70]);
+
+ act(() => {
+ root.render(
+
+
+
+ );
+ });
+ expect(mostRecentLayout).toEqual([100]);
+ });
+
describe("imperative handle API", () => {
it("should report the most recently rendered group id", () => {
const ref = createRef();
diff --git a/packages/react-resizable-panels/src/PanelGroup.ts b/packages/react-resizable-panels/src/PanelGroup.ts
index 469d0e62a..ce167c7ec 100644
--- a/packages/react-resizable-panels/src/PanelGroup.ts
+++ b/packages/react-resizable-panels/src/PanelGroup.ts
@@ -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 &&