Skip to content

Commit edf7f61

Browse files
authored
Support updates to either Group or Panel ids (#548)
Resolves #545
1 parent 3be6031 commit edf7f61

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- [#542](https://github.com/bvaughn/react-resizable-panels/pull/542): Clicks on higher `z-index` elements (e.g. modals) should not trigger separators behind them
66
- [#547](https://github.com/bvaughn/react-resizable-panels/pull/547): Don't re-mount Group when `defaultLayout` or `disableCursor` props change
7+
- [#548](https://github.com/bvaughn/react-resizable-panels/pull/548): Bugfix: Gracefully handle `Panel` id changes
78

89
## 4.0.8
910

lib/components/group/Group.test.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { render } from "@testing-library/react";
22
import { beforeEach, describe, expect, test, vi } from "vitest";
3+
import { eventEmitter } from "../../global/mutableState";
34
import { moveSeparator } from "../../global/test/moveSeparator";
5+
import { assert } from "../../utils/assert";
46
import { setElementBoundsFunction } from "../../utils/test/mockBoundingClientRect";
57
import { Panel } from "../panel/Panel";
68
import { Separator } from "../separator/Separator";
79
import { Group } from "./Group";
8-
import { assert } from "../../utils/assert";
9-
import { eventEmitter } from "../../global/mutableState";
1010

1111
describe("Group", () => {
1212
test("changes to defaultProps or disableCursor should not cause Group to remount", () => {
@@ -47,6 +47,36 @@ describe("Group", () => {
4747
removeListener();
4848
});
4949

50+
test("should support updates to either Group or Panel ids", () => {
51+
const { rerender } = render(
52+
<Group id="a">
53+
<Panel id="a-a" />
54+
<Panel id="a-b" />
55+
</Group>
56+
);
57+
58+
rerender(
59+
<Group id="a">
60+
<Panel id="b-a" />
61+
<Panel id="b-b" />
62+
</Group>
63+
);
64+
65+
rerender(
66+
<Group id="b">
67+
<Panel id="b-a" />
68+
<Panel id="b-b" />
69+
</Group>
70+
);
71+
72+
rerender(
73+
<Group id="c">
74+
<Panel id="c-a" />
75+
<Panel id="c-b" />
76+
</Group>
77+
);
78+
});
79+
5080
describe("onLayoutChange", () => {
5181
beforeEach(() => {
5282
setElementBoundsFunction((element) => {

lib/global/utils/layoutsEqual.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Layout } from "../../components/group/types";
55
const EMPTY: Layout = {};
66
const A: Layout = { a: 25, b: 75 };
77
const B: Layout = { a: 75, b: 25 };
8+
const C: Layout = { d: 25, e: 75 };
89

910
describe("layoutsEqual", () => {
1011
test.each([
@@ -14,7 +15,9 @@ describe("layoutsEqual", () => {
1415
[EMPTY, A, false],
1516
[A, EMPTY, false],
1617
[A, B, false],
17-
[B, A, false]
18+
[B, A, false],
19+
[A, C, false],
20+
[C, A, false]
1821
])("layoutsEqual: %o, %o -> %o", (a, b, expected) => {
1922
expect(layoutsEqual(a, b)).toBe(expected);
2023
});

lib/global/utils/layoutsEqual.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export function layoutsEqual(a: Layout, b: Layout): boolean {
77
}
88

99
for (const id in a) {
10-
if (compareLayoutNumbers(a[id], b[id]) !== 0) {
10+
// Edge case: Panel id has been changed
11+
if (b[id] === undefined || compareLayoutNumbers(a[id], b[id]) !== 0) {
1112
return false;
1213
}
1314
}

0 commit comments

Comments
 (0)