react-resizable-panels 2.0.6 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/react-resizable-panels.browser.cjs.js +1 -1
- package/dist/react-resizable-panels.browser.development.cjs.js +1 -1
- package/dist/react-resizable-panels.browser.development.esm.js +1 -1
- package/dist/react-resizable-panels.browser.esm.js +1 -1
- package/dist/react-resizable-panels.cjs.js +1 -1
- package/dist/react-resizable-panels.development.cjs.js +1 -1
- package/dist/react-resizable-panels.development.esm.js +1 -1
- package/dist/react-resizable-panels.development.node.cjs.js +1 -1
- package/dist/react-resizable-panels.development.node.esm.js +1 -1
- package/dist/react-resizable-panels.esm.js +1 -1
- package/dist/react-resizable-panels.node.cjs.js +1 -1
- package/dist/react-resizable-panels.node.esm.js +1 -1
- package/package.json +1 -1
- package/src/utils/computePanelFlexBoxStyle.test.ts +123 -0
- package/src/utils/computePanelFlexBoxStyle.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.0.7
|
|
4
|
+
|
|
5
|
+
- Group default layouts use `toPrecision` to avoid small layout shifts due to floating point precision differences between initial server rendering and client hydration (#295)
|
|
6
|
+
|
|
3
7
|
## 2.0.6
|
|
4
8
|
|
|
5
9
|
- Replace `useLayoutEffect` usage with SSR-safe wrapper hook (#294)
|
|
@@ -1245,7 +1245,7 @@ function computePanelFlexBoxStyle({
|
|
|
1245
1245
|
if (size == null) {
|
|
1246
1246
|
// Initial render (before panels have registered themselves)
|
|
1247
1247
|
// In order to support server rendering, fall back to default size if provided
|
|
1248
|
-
flexGrow = defaultSize
|
|
1248
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1249
1249
|
} else if (panelData.length === 1) {
|
|
1250
1250
|
// Special case: Single panel group should always fill full width/height
|
|
1251
1251
|
flexGrow = "1";
|
|
@@ -1261,7 +1261,7 @@ function computePanelFlexBoxStyle({
|
|
|
1261
1261
|
if (size == null) {
|
|
1262
1262
|
// Initial render (before panels have registered themselves)
|
|
1263
1263
|
// In order to support server rendering, fall back to default size if provided
|
|
1264
|
-
flexGrow = defaultSize
|
|
1264
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1265
1265
|
} else if (panelData.length === 1) {
|
|
1266
1266
|
// Special case: Single panel group should always fill full width/height
|
|
1267
1267
|
flexGrow = "1";
|
|
@@ -1237,7 +1237,7 @@ function computePanelFlexBoxStyle({
|
|
|
1237
1237
|
if (size == null) {
|
|
1238
1238
|
// Initial render (before panels have registered themselves)
|
|
1239
1239
|
// In order to support server rendering, fall back to default size if provided
|
|
1240
|
-
flexGrow = defaultSize
|
|
1240
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1241
1241
|
} else if (panelData.length === 1) {
|
|
1242
1242
|
// Special case: Single panel group should always fill full width/height
|
|
1243
1243
|
flexGrow = "1";
|
|
@@ -1221,7 +1221,7 @@ function computePanelFlexBoxStyle({
|
|
|
1221
1221
|
if (size == null) {
|
|
1222
1222
|
// Initial render (before panels have registered themselves)
|
|
1223
1223
|
// In order to support server rendering, fall back to default size if provided
|
|
1224
|
-
flexGrow = defaultSize
|
|
1224
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1225
1225
|
} else if (panelData.length === 1) {
|
|
1226
1226
|
// Special case: Single panel group should always fill full width/height
|
|
1227
1227
|
flexGrow = "1";
|
|
@@ -1247,7 +1247,7 @@ function computePanelFlexBoxStyle({
|
|
|
1247
1247
|
if (size == null) {
|
|
1248
1248
|
// Initial render (before panels have registered themselves)
|
|
1249
1249
|
// In order to support server rendering, fall back to default size if provided
|
|
1250
|
-
flexGrow = defaultSize
|
|
1250
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1251
1251
|
} else if (panelData.length === 1) {
|
|
1252
1252
|
// Special case: Single panel group should always fill full width/height
|
|
1253
1253
|
flexGrow = "1";
|
|
@@ -1268,7 +1268,7 @@ function computePanelFlexBoxStyle({
|
|
|
1268
1268
|
if (size == null) {
|
|
1269
1269
|
// Initial render (before panels have registered themselves)
|
|
1270
1270
|
// In order to support server rendering, fall back to default size if provided
|
|
1271
|
-
flexGrow = defaultSize
|
|
1271
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1272
1272
|
} else if (panelData.length === 1) {
|
|
1273
1273
|
// Special case: Single panel group should always fill full width/height
|
|
1274
1274
|
flexGrow = "1";
|
|
@@ -1244,7 +1244,7 @@ function computePanelFlexBoxStyle({
|
|
|
1244
1244
|
if (size == null) {
|
|
1245
1245
|
// Initial render (before panels have registered themselves)
|
|
1246
1246
|
// In order to support server rendering, fall back to default size if provided
|
|
1247
|
-
flexGrow = defaultSize
|
|
1247
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1248
1248
|
} else if (panelData.length === 1) {
|
|
1249
1249
|
// Special case: Single panel group should always fill full width/height
|
|
1250
1250
|
flexGrow = "1";
|
|
@@ -1106,7 +1106,7 @@ function computePanelFlexBoxStyle({
|
|
|
1106
1106
|
if (size == null) {
|
|
1107
1107
|
// Initial render (before panels have registered themselves)
|
|
1108
1108
|
// In order to support server rendering, fall back to default size if provided
|
|
1109
|
-
flexGrow = defaultSize
|
|
1109
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1110
1110
|
} else if (panelData.length === 1) {
|
|
1111
1111
|
// Special case: Single panel group should always fill full width/height
|
|
1112
1112
|
flexGrow = "1";
|
|
@@ -1082,7 +1082,7 @@ function computePanelFlexBoxStyle({
|
|
|
1082
1082
|
if (size == null) {
|
|
1083
1083
|
// Initial render (before panels have registered themselves)
|
|
1084
1084
|
// In order to support server rendering, fall back to default size if provided
|
|
1085
|
-
flexGrow = defaultSize
|
|
1085
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1086
1086
|
} else if (panelData.length === 1) {
|
|
1087
1087
|
// Special case: Single panel group should always fill full width/height
|
|
1088
1088
|
flexGrow = "1";
|
|
@@ -1223,7 +1223,7 @@ function computePanelFlexBoxStyle({
|
|
|
1223
1223
|
if (size == null) {
|
|
1224
1224
|
// Initial render (before panels have registered themselves)
|
|
1225
1225
|
// In order to support server rendering, fall back to default size if provided
|
|
1226
|
-
flexGrow = defaultSize
|
|
1226
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1227
1227
|
} else if (panelData.length === 1) {
|
|
1228
1228
|
// Special case: Single panel group should always fill full width/height
|
|
1229
1229
|
flexGrow = "1";
|
|
@@ -1095,7 +1095,7 @@ function computePanelFlexBoxStyle({
|
|
|
1095
1095
|
if (size == null) {
|
|
1096
1096
|
// Initial render (before panels have registered themselves)
|
|
1097
1097
|
// In order to support server rendering, fall back to default size if provided
|
|
1098
|
-
flexGrow = defaultSize
|
|
1098
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1099
1099
|
} else if (panelData.length === 1) {
|
|
1100
1100
|
// Special case: Single panel group should always fill full width/height
|
|
1101
1101
|
flexGrow = "1";
|
|
@@ -1071,7 +1071,7 @@ function computePanelFlexBoxStyle({
|
|
|
1071
1071
|
if (size == null) {
|
|
1072
1072
|
// Initial render (before panels have registered themselves)
|
|
1073
1073
|
// In order to support server rendering, fall back to default size if provided
|
|
1074
|
-
flexGrow = defaultSize
|
|
1074
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1075
1075
|
} else if (panelData.length === 1) {
|
|
1076
1076
|
// Special case: Single panel group should always fill full width/height
|
|
1077
1077
|
flexGrow = "1";
|
package/package.json
CHANGED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { PanelConstraints, PanelData } from "../Panel";
|
|
2
|
+
import { computePanelFlexBoxStyle } from "./computePanelFlexBoxStyle";
|
|
3
|
+
|
|
4
|
+
describe("computePanelFlexBoxStyle", () => {
|
|
5
|
+
function createPanelData(constraints: PanelConstraints = {}): PanelData {
|
|
6
|
+
return {
|
|
7
|
+
callbacks: {},
|
|
8
|
+
constraints,
|
|
9
|
+
id: "fake",
|
|
10
|
+
idIsFromProps: false,
|
|
11
|
+
order: undefined,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
it("should observe a panel's default size if group layout has not yet been computed", () => {
|
|
16
|
+
expect(
|
|
17
|
+
computePanelFlexBoxStyle({
|
|
18
|
+
defaultSize: 0.1233456789,
|
|
19
|
+
dragState: null,
|
|
20
|
+
layout: [],
|
|
21
|
+
panelData: [
|
|
22
|
+
createPanelData({
|
|
23
|
+
defaultSize: 0.1233456789,
|
|
24
|
+
}),
|
|
25
|
+
createPanelData(),
|
|
26
|
+
],
|
|
27
|
+
panelIndex: 0,
|
|
28
|
+
precision: 2,
|
|
29
|
+
})
|
|
30
|
+
).toMatchInlineSnapshot(`
|
|
31
|
+
{
|
|
32
|
+
"flexBasis": 0,
|
|
33
|
+
"flexGrow": "0.12",
|
|
34
|
+
"flexShrink": 1,
|
|
35
|
+
"overflow": "hidden",
|
|
36
|
+
"pointerEvents": undefined,
|
|
37
|
+
}
|
|
38
|
+
`);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should always fill the full width for single-panel groups", () => {
|
|
42
|
+
expect(
|
|
43
|
+
computePanelFlexBoxStyle({
|
|
44
|
+
defaultSize: undefined,
|
|
45
|
+
dragState: null,
|
|
46
|
+
layout: [],
|
|
47
|
+
panelData: [createPanelData()],
|
|
48
|
+
panelIndex: 0,
|
|
49
|
+
precision: 2,
|
|
50
|
+
})
|
|
51
|
+
).toMatchInlineSnapshot(`
|
|
52
|
+
{
|
|
53
|
+
"flexBasis": 0,
|
|
54
|
+
"flexGrow": "1",
|
|
55
|
+
"flexShrink": 1,
|
|
56
|
+
"overflow": "hidden",
|
|
57
|
+
"pointerEvents": undefined,
|
|
58
|
+
}
|
|
59
|
+
`);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should round sizes to avoid floating point precision errors", () => {
|
|
63
|
+
const layout = [0.25435, 0.5758, 0.1698];
|
|
64
|
+
const panelData = [createPanelData(), createPanelData(), createPanelData()];
|
|
65
|
+
|
|
66
|
+
expect(
|
|
67
|
+
computePanelFlexBoxStyle({
|
|
68
|
+
defaultSize: undefined,
|
|
69
|
+
dragState: null,
|
|
70
|
+
layout,
|
|
71
|
+
panelData,
|
|
72
|
+
panelIndex: 0,
|
|
73
|
+
precision: 2,
|
|
74
|
+
})
|
|
75
|
+
).toMatchInlineSnapshot(`
|
|
76
|
+
{
|
|
77
|
+
"flexBasis": 0,
|
|
78
|
+
"flexGrow": "0.25",
|
|
79
|
+
"flexShrink": 1,
|
|
80
|
+
"overflow": "hidden",
|
|
81
|
+
"pointerEvents": undefined,
|
|
82
|
+
}
|
|
83
|
+
`);
|
|
84
|
+
|
|
85
|
+
expect(
|
|
86
|
+
computePanelFlexBoxStyle({
|
|
87
|
+
defaultSize: undefined,
|
|
88
|
+
dragState: null,
|
|
89
|
+
layout,
|
|
90
|
+
panelData,
|
|
91
|
+
panelIndex: 1,
|
|
92
|
+
precision: 2,
|
|
93
|
+
})
|
|
94
|
+
).toMatchInlineSnapshot(`
|
|
95
|
+
{
|
|
96
|
+
"flexBasis": 0,
|
|
97
|
+
"flexGrow": "0.58",
|
|
98
|
+
"flexShrink": 1,
|
|
99
|
+
"overflow": "hidden",
|
|
100
|
+
"pointerEvents": undefined,
|
|
101
|
+
}
|
|
102
|
+
`);
|
|
103
|
+
|
|
104
|
+
expect(
|
|
105
|
+
computePanelFlexBoxStyle({
|
|
106
|
+
defaultSize: undefined,
|
|
107
|
+
dragState: null,
|
|
108
|
+
layout,
|
|
109
|
+
panelData,
|
|
110
|
+
panelIndex: 2,
|
|
111
|
+
precision: 2,
|
|
112
|
+
})
|
|
113
|
+
).toMatchInlineSnapshot(`
|
|
114
|
+
{
|
|
115
|
+
"flexBasis": 0,
|
|
116
|
+
"flexGrow": "0.17",
|
|
117
|
+
"flexShrink": 1,
|
|
118
|
+
"overflow": "hidden",
|
|
119
|
+
"pointerEvents": undefined,
|
|
120
|
+
}
|
|
121
|
+
`);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -26,7 +26,8 @@ export function computePanelFlexBoxStyle({
|
|
|
26
26
|
if (size == null) {
|
|
27
27
|
// Initial render (before panels have registered themselves)
|
|
28
28
|
// In order to support server rendering, fall back to default size if provided
|
|
29
|
-
flexGrow =
|
|
29
|
+
flexGrow =
|
|
30
|
+
defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
30
31
|
} else if (panelData.length === 1) {
|
|
31
32
|
// Special case: Single panel group should always fill full width/height
|
|
32
33
|
flexGrow = "1";
|