react-resizable-panels 0.0.60 → 0.0.61

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.
@@ -643,6 +643,7 @@ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
643
643
 
644
644
  function useWindowSplitterPanelGroupBehavior({
645
645
  committedValuesRef,
646
+ eagerValuesRef,
646
647
  groupId,
647
648
  layout,
648
649
  panelDataArray,
@@ -654,7 +655,7 @@ function useWindowSplitterPanelGroupBehavior({
654
655
  useEffect(() => {
655
656
  const {
656
657
  panelDataArray
657
- } = committedValuesRef.current;
658
+ } = eagerValuesRef.current;
658
659
  const groupElement = getPanelGroupElement(groupId);
659
660
  assert(groupElement != null, `No group found for id "${groupId}"`);
660
661
  const handles = getResizeHandleElementsForGroup(groupId);
@@ -712,7 +713,7 @@ function useWindowSplitterPanelGroupBehavior({
712
713
  return () => {
713
714
  cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
714
715
  };
715
- }, [committedValuesRef, groupId, layout, panelDataArray, setLayout]);
716
+ }, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
716
717
  }
717
718
 
718
719
  function areEqual(arrayA, arrayB) {
@@ -1254,11 +1255,13 @@ function PanelGroupWithForwardedRef({
1254
1255
  id: groupId,
1255
1256
  keyboardResizeByPercentage,
1256
1257
  keyboardResizeByPixels,
1257
- layout,
1258
1258
  onLayout,
1259
- panelDataArray: [],
1260
1259
  storage
1261
1260
  });
1261
+ const eagerValuesRef = useRef({
1262
+ layout,
1263
+ panelDataArray: []
1264
+ });
1262
1265
  const devWarningsRef = useRef({
1263
1266
  didLogIdAndOrderWarning: false,
1264
1267
  didLogPanelConstraintsWarning: false,
@@ -1268,9 +1271,11 @@ function PanelGroupWithForwardedRef({
1268
1271
  getId: () => committedValuesRef.current.id,
1269
1272
  getLayout: () => {
1270
1273
  const {
1271
- id: groupId,
1272
- layout
1274
+ id: groupId
1273
1275
  } = committedValuesRef.current;
1276
+ const {
1277
+ layout
1278
+ } = eagerValuesRef.current;
1274
1279
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1275
1280
  return layout.map(sizePercentage => {
1276
1281
  return {
@@ -1282,10 +1287,12 @@ function PanelGroupWithForwardedRef({
1282
1287
  setLayout: mixedSizes => {
1283
1288
  const {
1284
1289
  id: groupId,
1290
+ onLayout
1291
+ } = committedValuesRef.current;
1292
+ const {
1285
1293
  layout: prevLayout,
1286
- onLayout,
1287
1294
  panelDataArray
1288
- } = committedValuesRef.current;
1295
+ } = eagerValuesRef.current;
1289
1296
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1290
1297
  const unsafeLayout = mixedSizes.map(mixedSize => getPercentageSizeFromMixedSizes(mixedSize, groupSizePixels));
1291
1298
  const safeLayout = validatePanelGroupLayout({
@@ -1295,7 +1302,7 @@ function PanelGroupWithForwardedRef({
1295
1302
  });
1296
1303
  if (!areEqual(prevLayout, safeLayout)) {
1297
1304
  setLayout(safeLayout);
1298
- committedValuesRef.current.layout = safeLayout;
1305
+ eagerValuesRef.current.layout = safeLayout;
1299
1306
  if (onLayout) {
1300
1307
  onLayout(safeLayout.map(sizePercentage => ({
1301
1308
  sizePercentage,
@@ -1309,15 +1316,16 @@ function PanelGroupWithForwardedRef({
1309
1316
 
1310
1317
  useWindowSplitterPanelGroupBehavior({
1311
1318
  committedValuesRef,
1319
+ eagerValuesRef,
1312
1320
  groupId,
1313
1321
  layout,
1314
- panelDataArray: committedValuesRef.current.panelDataArray,
1322
+ panelDataArray: eagerValuesRef.current.panelDataArray,
1315
1323
  setLayout
1316
1324
  });
1317
1325
  useEffect(() => {
1318
1326
  const {
1319
1327
  panelDataArray
1320
- } = committedValuesRef.current;
1328
+ } = eagerValuesRef.current;
1321
1329
 
1322
1330
  // If this panel has been configured to persist sizing information, save sizes to local storage.
1323
1331
  if (autoSaveId) {
@@ -1338,7 +1346,7 @@ function PanelGroupWithForwardedRef({
1338
1346
  {
1339
1347
  const {
1340
1348
  panelDataArray
1341
- } = committedValuesRef.current;
1349
+ } = eagerValuesRef.current;
1342
1350
  const {
1343
1351
  didLogIdAndOrderWarning,
1344
1352
  didLogPanelConstraintsWarning,
@@ -1381,11 +1389,13 @@ function PanelGroupWithForwardedRef({
1381
1389
 
1382
1390
  // External APIs are safe to memoize via committed values ref
1383
1391
  const collapsePanel = useCallback(panelData => {
1392
+ const {
1393
+ onLayout
1394
+ } = committedValuesRef.current;
1384
1395
  const {
1385
1396
  layout: prevLayout,
1386
- onLayout,
1387
1397
  panelDataArray
1388
- } = committedValuesRef.current;
1398
+ } = eagerValuesRef.current;
1389
1399
  if (panelData.constraints.collapsible) {
1390
1400
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1391
1401
  const {
@@ -1410,7 +1420,7 @@ function PanelGroupWithForwardedRef({
1410
1420
  });
1411
1421
  if (!compareLayouts(prevLayout, nextLayout)) {
1412
1422
  setLayout(nextLayout);
1413
- committedValuesRef.current.layout = nextLayout;
1423
+ eagerValuesRef.current.layout = nextLayout;
1414
1424
  if (onLayout) {
1415
1425
  onLayout(nextLayout.map(sizePercentage => ({
1416
1426
  sizePercentage,
@@ -1425,11 +1435,13 @@ function PanelGroupWithForwardedRef({
1425
1435
 
1426
1436
  // External APIs are safe to memoize via committed values ref
1427
1437
  const expandPanel = useCallback(panelData => {
1438
+ const {
1439
+ onLayout
1440
+ } = committedValuesRef.current;
1428
1441
  const {
1429
1442
  layout: prevLayout,
1430
- onLayout,
1431
1443
  panelDataArray
1432
- } = committedValuesRef.current;
1444
+ } = eagerValuesRef.current;
1433
1445
  if (panelData.constraints.collapsible) {
1434
1446
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1435
1447
  const {
@@ -1455,7 +1467,7 @@ function PanelGroupWithForwardedRef({
1455
1467
  });
1456
1468
  if (!compareLayouts(prevLayout, nextLayout)) {
1457
1469
  setLayout(nextLayout);
1458
- committedValuesRef.current.layout = nextLayout;
1470
+ eagerValuesRef.current.layout = nextLayout;
1459
1471
  if (onLayout) {
1460
1472
  onLayout(nextLayout.map(sizePercentage => ({
1461
1473
  sizePercentage,
@@ -1473,7 +1485,7 @@ function PanelGroupWithForwardedRef({
1473
1485
  const {
1474
1486
  layout,
1475
1487
  panelDataArray
1476
- } = committedValuesRef.current;
1488
+ } = eagerValuesRef.current;
1477
1489
  const {
1478
1490
  panelSizePercentage,
1479
1491
  panelSizePixels
@@ -1488,7 +1500,7 @@ function PanelGroupWithForwardedRef({
1488
1500
  const getPanelStyle = useCallback(panelData => {
1489
1501
  const {
1490
1502
  panelDataArray
1491
- } = committedValuesRef.current;
1503
+ } = eagerValuesRef.current;
1492
1504
  const panelIndex = panelDataArray.indexOf(panelData);
1493
1505
  return computePanelFlexBoxStyle({
1494
1506
  dragState,
@@ -1503,7 +1515,7 @@ function PanelGroupWithForwardedRef({
1503
1515
  const {
1504
1516
  layout,
1505
1517
  panelDataArray
1506
- } = committedValuesRef.current;
1518
+ } = eagerValuesRef.current;
1507
1519
  const {
1508
1520
  collapsedSizePercentage,
1509
1521
  collapsible,
@@ -1517,7 +1529,7 @@ function PanelGroupWithForwardedRef({
1517
1529
  const {
1518
1530
  layout,
1519
1531
  panelDataArray
1520
- } = committedValuesRef.current;
1532
+ } = eagerValuesRef.current;
1521
1533
  const {
1522
1534
  collapsedSizePercentage,
1523
1535
  collapsible,
@@ -1529,11 +1541,13 @@ function PanelGroupWithForwardedRef({
1529
1541
  const {
1530
1542
  autoSaveId,
1531
1543
  id: groupId,
1532
- layout: prevLayout,
1533
1544
  onLayout,
1534
- panelDataArray,
1535
1545
  storage
1536
1546
  } = committedValuesRef.current;
1547
+ const {
1548
+ layout: prevLayout,
1549
+ panelDataArray
1550
+ } = eagerValuesRef.current;
1537
1551
  panelDataArray.push(panelData);
1538
1552
  panelDataArray.sort((panelA, panelB) => {
1539
1553
  const orderA = panelA.order;
@@ -1585,9 +1599,13 @@ function PanelGroupWithForwardedRef({
1585
1599
  layout: unsafeLayout,
1586
1600
  panelConstraints: panelDataArray.map(panelData => panelData.constraints)
1587
1601
  });
1602
+
1603
+ // Offscreen mode makes this a bit weird;
1604
+ // Panels unregister when hidden and re-register when shown again,
1605
+ // but the overall layout doesn't change between these two cases.
1606
+ setLayout(nextLayout);
1607
+ eagerValuesRef.current.layout = nextLayout;
1588
1608
  if (!areEqual(prevLayout, nextLayout)) {
1589
- setLayout(nextLayout);
1590
- committedValuesRef.current.layout = nextLayout;
1591
1609
  if (onLayout) {
1592
1610
  onLayout(nextLayout.map(sizePercentage => ({
1593
1611
  sizePercentage,
@@ -1606,10 +1624,12 @@ function PanelGroupWithForwardedRef({
1606
1624
  id: groupId,
1607
1625
  keyboardResizeByPercentage,
1608
1626
  keyboardResizeByPixels,
1609
- onLayout,
1610
- panelDataArray,
1611
- layout: prevLayout
1627
+ onLayout
1612
1628
  } = committedValuesRef.current;
1629
+ const {
1630
+ layout: prevLayout,
1631
+ panelDataArray
1632
+ } = eagerValuesRef.current;
1613
1633
  const {
1614
1634
  initialLayout
1615
1635
  } = dragState !== null && dragState !== void 0 ? dragState : {};
@@ -1665,7 +1685,7 @@ function PanelGroupWithForwardedRef({
1665
1685
  }
1666
1686
  if (layoutChanged) {
1667
1687
  setLayout(nextLayout);
1668
- committedValuesRef.current.layout = nextLayout;
1688
+ eagerValuesRef.current.layout = nextLayout;
1669
1689
  if (onLayout) {
1670
1690
  onLayout(nextLayout.map(sizePercentage => ({
1671
1691
  sizePercentage,
@@ -1679,11 +1699,13 @@ function PanelGroupWithForwardedRef({
1679
1699
 
1680
1700
  // External APIs are safe to memoize via committed values ref
1681
1701
  const resizePanel = useCallback((panelData, mixedSizes) => {
1702
+ const {
1703
+ onLayout
1704
+ } = committedValuesRef.current;
1682
1705
  const {
1683
1706
  layout: prevLayout,
1684
- onLayout,
1685
1707
  panelDataArray
1686
- } = committedValuesRef.current;
1708
+ } = eagerValuesRef.current;
1687
1709
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1688
1710
  const {
1689
1711
  groupSizePixels,
@@ -1703,7 +1725,7 @@ function PanelGroupWithForwardedRef({
1703
1725
  });
1704
1726
  if (!compareLayouts(prevLayout, nextLayout)) {
1705
1727
  setLayout(nextLayout);
1706
- committedValuesRef.current.layout = nextLayout;
1728
+ eagerValuesRef.current.layout = nextLayout;
1707
1729
  if (onLayout) {
1708
1730
  onLayout(nextLayout.map(sizePercentage => ({
1709
1731
  sizePercentage,
@@ -1715,9 +1737,11 @@ function PanelGroupWithForwardedRef({
1715
1737
  }, [groupId]);
1716
1738
  const startDragging = useCallback((dragHandleId, event) => {
1717
1739
  const {
1718
- direction,
1719
- layout
1740
+ direction
1720
1741
  } = committedValuesRef.current;
1742
+ const {
1743
+ layout
1744
+ } = eagerValuesRef.current;
1721
1745
  const handleElement = getResizeHandleElement(dragHandleId);
1722
1746
  const initialCursorPosition = getResizeEventCursorPosition(direction, event);
1723
1747
  setDragState({
@@ -1738,10 +1762,12 @@ function PanelGroupWithForwardedRef({
1738
1762
  const unregisterPanel = useCallback(panelData => {
1739
1763
  const {
1740
1764
  id: groupId,
1765
+ onLayout
1766
+ } = committedValuesRef.current;
1767
+ const {
1741
1768
  layout: prevLayout,
1742
- onLayout,
1743
1769
  panelDataArray
1744
- } = committedValuesRef.current;
1770
+ } = eagerValuesRef.current;
1745
1771
  const index = panelDataArray.indexOf(panelData);
1746
1772
  if (index >= 0) {
1747
1773
  panelDataArray.splice(index, 1);
@@ -1758,7 +1784,7 @@ function PanelGroupWithForwardedRef({
1758
1784
  const {
1759
1785
  pendingPanelIds
1760
1786
  } = unregisterPanelRef.current;
1761
- panelIdToLastNotifiedMixedSizesMapRef.current;
1787
+ const map = panelIdToLastNotifiedMixedSizesMapRef.current;
1762
1788
 
1763
1789
  // TRICKY
1764
1790
  // Strict effects mode
@@ -1774,7 +1800,7 @@ function PanelGroupWithForwardedRef({
1774
1800
  // When a panel is removed from the group, we should delete the most recent prev-size entry for it.
1775
1801
  // If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
1776
1802
  // Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
1777
- delete panelIdToLastNotifiedMixedSizesMapRef.current[panelData.id];
1803
+ delete map[panelData.id];
1778
1804
  }
1779
1805
  });
1780
1806
  if (!unmountDueToStrictMode) {
@@ -1799,7 +1825,7 @@ function PanelGroupWithForwardedRef({
1799
1825
  });
1800
1826
  if (!areEqual(prevLayout, nextLayout)) {
1801
1827
  setLayout(nextLayout);
1802
- committedValuesRef.current.layout = nextLayout;
1828
+ eagerValuesRef.current.layout = nextLayout;
1803
1829
  if (onLayout) {
1804
1830
  onLayout(nextLayout.map(sizePercentage => ({
1805
1831
  sizePercentage,
@@ -619,6 +619,7 @@ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
619
619
 
620
620
  function useWindowSplitterPanelGroupBehavior({
621
621
  committedValuesRef,
622
+ eagerValuesRef,
622
623
  groupId,
623
624
  layout,
624
625
  panelDataArray,
@@ -630,7 +631,7 @@ function useWindowSplitterPanelGroupBehavior({
630
631
  useEffect(() => {
631
632
  const {
632
633
  panelDataArray
633
- } = committedValuesRef.current;
634
+ } = eagerValuesRef.current;
634
635
  const groupElement = getPanelGroupElement(groupId);
635
636
  assert(groupElement != null, `No group found for id "${groupId}"`);
636
637
  const handles = getResizeHandleElementsForGroup(groupId);
@@ -688,7 +689,7 @@ function useWindowSplitterPanelGroupBehavior({
688
689
  return () => {
689
690
  cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
690
691
  };
691
- }, [committedValuesRef, groupId, layout, panelDataArray, setLayout]);
692
+ }, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
692
693
  }
693
694
 
694
695
  function areEqual(arrayA, arrayB) {
@@ -1230,11 +1231,13 @@ function PanelGroupWithForwardedRef({
1230
1231
  id: groupId,
1231
1232
  keyboardResizeByPercentage,
1232
1233
  keyboardResizeByPixels,
1233
- layout,
1234
1234
  onLayout,
1235
- panelDataArray: [],
1236
1235
  storage
1237
1236
  });
1237
+ const eagerValuesRef = useRef({
1238
+ layout,
1239
+ panelDataArray: []
1240
+ });
1238
1241
  const devWarningsRef = useRef({
1239
1242
  didLogIdAndOrderWarning: false,
1240
1243
  didLogPanelConstraintsWarning: false,
@@ -1244,9 +1247,11 @@ function PanelGroupWithForwardedRef({
1244
1247
  getId: () => committedValuesRef.current.id,
1245
1248
  getLayout: () => {
1246
1249
  const {
1247
- id: groupId,
1248
- layout
1250
+ id: groupId
1249
1251
  } = committedValuesRef.current;
1252
+ const {
1253
+ layout
1254
+ } = eagerValuesRef.current;
1250
1255
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1251
1256
  return layout.map(sizePercentage => {
1252
1257
  return {
@@ -1258,10 +1263,12 @@ function PanelGroupWithForwardedRef({
1258
1263
  setLayout: mixedSizes => {
1259
1264
  const {
1260
1265
  id: groupId,
1266
+ onLayout
1267
+ } = committedValuesRef.current;
1268
+ const {
1261
1269
  layout: prevLayout,
1262
- onLayout,
1263
1270
  panelDataArray
1264
- } = committedValuesRef.current;
1271
+ } = eagerValuesRef.current;
1265
1272
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1266
1273
  const unsafeLayout = mixedSizes.map(mixedSize => getPercentageSizeFromMixedSizes(mixedSize, groupSizePixels));
1267
1274
  const safeLayout = validatePanelGroupLayout({
@@ -1271,7 +1278,7 @@ function PanelGroupWithForwardedRef({
1271
1278
  });
1272
1279
  if (!areEqual(prevLayout, safeLayout)) {
1273
1280
  setLayout(safeLayout);
1274
- committedValuesRef.current.layout = safeLayout;
1281
+ eagerValuesRef.current.layout = safeLayout;
1275
1282
  if (onLayout) {
1276
1283
  onLayout(safeLayout.map(sizePercentage => ({
1277
1284
  sizePercentage,
@@ -1285,15 +1292,16 @@ function PanelGroupWithForwardedRef({
1285
1292
 
1286
1293
  useWindowSplitterPanelGroupBehavior({
1287
1294
  committedValuesRef,
1295
+ eagerValuesRef,
1288
1296
  groupId,
1289
1297
  layout,
1290
- panelDataArray: committedValuesRef.current.panelDataArray,
1298
+ panelDataArray: eagerValuesRef.current.panelDataArray,
1291
1299
  setLayout
1292
1300
  });
1293
1301
  useEffect(() => {
1294
1302
  const {
1295
1303
  panelDataArray
1296
- } = committedValuesRef.current;
1304
+ } = eagerValuesRef.current;
1297
1305
 
1298
1306
  // If this panel has been configured to persist sizing information, save sizes to local storage.
1299
1307
  if (autoSaveId) {
@@ -1314,7 +1322,7 @@ function PanelGroupWithForwardedRef({
1314
1322
  {
1315
1323
  const {
1316
1324
  panelDataArray
1317
- } = committedValuesRef.current;
1325
+ } = eagerValuesRef.current;
1318
1326
  const {
1319
1327
  didLogIdAndOrderWarning,
1320
1328
  didLogPanelConstraintsWarning,
@@ -1357,11 +1365,13 @@ function PanelGroupWithForwardedRef({
1357
1365
 
1358
1366
  // External APIs are safe to memoize via committed values ref
1359
1367
  const collapsePanel = useCallback(panelData => {
1368
+ const {
1369
+ onLayout
1370
+ } = committedValuesRef.current;
1360
1371
  const {
1361
1372
  layout: prevLayout,
1362
- onLayout,
1363
1373
  panelDataArray
1364
- } = committedValuesRef.current;
1374
+ } = eagerValuesRef.current;
1365
1375
  if (panelData.constraints.collapsible) {
1366
1376
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1367
1377
  const {
@@ -1386,7 +1396,7 @@ function PanelGroupWithForwardedRef({
1386
1396
  });
1387
1397
  if (!compareLayouts(prevLayout, nextLayout)) {
1388
1398
  setLayout(nextLayout);
1389
- committedValuesRef.current.layout = nextLayout;
1399
+ eagerValuesRef.current.layout = nextLayout;
1390
1400
  if (onLayout) {
1391
1401
  onLayout(nextLayout.map(sizePercentage => ({
1392
1402
  sizePercentage,
@@ -1401,11 +1411,13 @@ function PanelGroupWithForwardedRef({
1401
1411
 
1402
1412
  // External APIs are safe to memoize via committed values ref
1403
1413
  const expandPanel = useCallback(panelData => {
1414
+ const {
1415
+ onLayout
1416
+ } = committedValuesRef.current;
1404
1417
  const {
1405
1418
  layout: prevLayout,
1406
- onLayout,
1407
1419
  panelDataArray
1408
- } = committedValuesRef.current;
1420
+ } = eagerValuesRef.current;
1409
1421
  if (panelData.constraints.collapsible) {
1410
1422
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1411
1423
  const {
@@ -1431,7 +1443,7 @@ function PanelGroupWithForwardedRef({
1431
1443
  });
1432
1444
  if (!compareLayouts(prevLayout, nextLayout)) {
1433
1445
  setLayout(nextLayout);
1434
- committedValuesRef.current.layout = nextLayout;
1446
+ eagerValuesRef.current.layout = nextLayout;
1435
1447
  if (onLayout) {
1436
1448
  onLayout(nextLayout.map(sizePercentage => ({
1437
1449
  sizePercentage,
@@ -1449,7 +1461,7 @@ function PanelGroupWithForwardedRef({
1449
1461
  const {
1450
1462
  layout,
1451
1463
  panelDataArray
1452
- } = committedValuesRef.current;
1464
+ } = eagerValuesRef.current;
1453
1465
  const {
1454
1466
  panelSizePercentage,
1455
1467
  panelSizePixels
@@ -1464,7 +1476,7 @@ function PanelGroupWithForwardedRef({
1464
1476
  const getPanelStyle = useCallback(panelData => {
1465
1477
  const {
1466
1478
  panelDataArray
1467
- } = committedValuesRef.current;
1479
+ } = eagerValuesRef.current;
1468
1480
  const panelIndex = panelDataArray.indexOf(panelData);
1469
1481
  return computePanelFlexBoxStyle({
1470
1482
  dragState,
@@ -1479,7 +1491,7 @@ function PanelGroupWithForwardedRef({
1479
1491
  const {
1480
1492
  layout,
1481
1493
  panelDataArray
1482
- } = committedValuesRef.current;
1494
+ } = eagerValuesRef.current;
1483
1495
  const {
1484
1496
  collapsedSizePercentage,
1485
1497
  collapsible,
@@ -1493,7 +1505,7 @@ function PanelGroupWithForwardedRef({
1493
1505
  const {
1494
1506
  layout,
1495
1507
  panelDataArray
1496
- } = committedValuesRef.current;
1508
+ } = eagerValuesRef.current;
1497
1509
  const {
1498
1510
  collapsedSizePercentage,
1499
1511
  collapsible,
@@ -1505,11 +1517,13 @@ function PanelGroupWithForwardedRef({
1505
1517
  const {
1506
1518
  autoSaveId,
1507
1519
  id: groupId,
1508
- layout: prevLayout,
1509
1520
  onLayout,
1510
- panelDataArray,
1511
1521
  storage
1512
1522
  } = committedValuesRef.current;
1523
+ const {
1524
+ layout: prevLayout,
1525
+ panelDataArray
1526
+ } = eagerValuesRef.current;
1513
1527
  panelDataArray.push(panelData);
1514
1528
  panelDataArray.sort((panelA, panelB) => {
1515
1529
  const orderA = panelA.order;
@@ -1561,9 +1575,13 @@ function PanelGroupWithForwardedRef({
1561
1575
  layout: unsafeLayout,
1562
1576
  panelConstraints: panelDataArray.map(panelData => panelData.constraints)
1563
1577
  });
1578
+
1579
+ // Offscreen mode makes this a bit weird;
1580
+ // Panels unregister when hidden and re-register when shown again,
1581
+ // but the overall layout doesn't change between these two cases.
1582
+ setLayout(nextLayout);
1583
+ eagerValuesRef.current.layout = nextLayout;
1564
1584
  if (!areEqual(prevLayout, nextLayout)) {
1565
- setLayout(nextLayout);
1566
- committedValuesRef.current.layout = nextLayout;
1567
1585
  if (onLayout) {
1568
1586
  onLayout(nextLayout.map(sizePercentage => ({
1569
1587
  sizePercentage,
@@ -1582,10 +1600,12 @@ function PanelGroupWithForwardedRef({
1582
1600
  id: groupId,
1583
1601
  keyboardResizeByPercentage,
1584
1602
  keyboardResizeByPixels,
1585
- onLayout,
1586
- panelDataArray,
1587
- layout: prevLayout
1603
+ onLayout
1588
1604
  } = committedValuesRef.current;
1605
+ const {
1606
+ layout: prevLayout,
1607
+ panelDataArray
1608
+ } = eagerValuesRef.current;
1589
1609
  const {
1590
1610
  initialLayout
1591
1611
  } = dragState !== null && dragState !== void 0 ? dragState : {};
@@ -1641,7 +1661,7 @@ function PanelGroupWithForwardedRef({
1641
1661
  }
1642
1662
  if (layoutChanged) {
1643
1663
  setLayout(nextLayout);
1644
- committedValuesRef.current.layout = nextLayout;
1664
+ eagerValuesRef.current.layout = nextLayout;
1645
1665
  if (onLayout) {
1646
1666
  onLayout(nextLayout.map(sizePercentage => ({
1647
1667
  sizePercentage,
@@ -1655,11 +1675,13 @@ function PanelGroupWithForwardedRef({
1655
1675
 
1656
1676
  // External APIs are safe to memoize via committed values ref
1657
1677
  const resizePanel = useCallback((panelData, mixedSizes) => {
1678
+ const {
1679
+ onLayout
1680
+ } = committedValuesRef.current;
1658
1681
  const {
1659
1682
  layout: prevLayout,
1660
- onLayout,
1661
1683
  panelDataArray
1662
- } = committedValuesRef.current;
1684
+ } = eagerValuesRef.current;
1663
1685
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1664
1686
  const {
1665
1687
  groupSizePixels,
@@ -1679,7 +1701,7 @@ function PanelGroupWithForwardedRef({
1679
1701
  });
1680
1702
  if (!compareLayouts(prevLayout, nextLayout)) {
1681
1703
  setLayout(nextLayout);
1682
- committedValuesRef.current.layout = nextLayout;
1704
+ eagerValuesRef.current.layout = nextLayout;
1683
1705
  if (onLayout) {
1684
1706
  onLayout(nextLayout.map(sizePercentage => ({
1685
1707
  sizePercentage,
@@ -1691,9 +1713,11 @@ function PanelGroupWithForwardedRef({
1691
1713
  }, [groupId]);
1692
1714
  const startDragging = useCallback((dragHandleId, event) => {
1693
1715
  const {
1694
- direction,
1695
- layout
1716
+ direction
1696
1717
  } = committedValuesRef.current;
1718
+ const {
1719
+ layout
1720
+ } = eagerValuesRef.current;
1697
1721
  const handleElement = getResizeHandleElement(dragHandleId);
1698
1722
  const initialCursorPosition = getResizeEventCursorPosition(direction, event);
1699
1723
  setDragState({
@@ -1714,10 +1738,12 @@ function PanelGroupWithForwardedRef({
1714
1738
  const unregisterPanel = useCallback(panelData => {
1715
1739
  const {
1716
1740
  id: groupId,
1741
+ onLayout
1742
+ } = committedValuesRef.current;
1743
+ const {
1717
1744
  layout: prevLayout,
1718
- onLayout,
1719
1745
  panelDataArray
1720
- } = committedValuesRef.current;
1746
+ } = eagerValuesRef.current;
1721
1747
  const index = panelDataArray.indexOf(panelData);
1722
1748
  if (index >= 0) {
1723
1749
  panelDataArray.splice(index, 1);
@@ -1734,7 +1760,7 @@ function PanelGroupWithForwardedRef({
1734
1760
  const {
1735
1761
  pendingPanelIds
1736
1762
  } = unregisterPanelRef.current;
1737
- panelIdToLastNotifiedMixedSizesMapRef.current;
1763
+ const map = panelIdToLastNotifiedMixedSizesMapRef.current;
1738
1764
 
1739
1765
  // TRICKY
1740
1766
  // Strict effects mode
@@ -1750,7 +1776,7 @@ function PanelGroupWithForwardedRef({
1750
1776
  // When a panel is removed from the group, we should delete the most recent prev-size entry for it.
1751
1777
  // If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
1752
1778
  // Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
1753
- delete panelIdToLastNotifiedMixedSizesMapRef.current[panelData.id];
1779
+ delete map[panelData.id];
1754
1780
  }
1755
1781
  });
1756
1782
  if (!unmountDueToStrictMode) {
@@ -1775,7 +1801,7 @@ function PanelGroupWithForwardedRef({
1775
1801
  });
1776
1802
  if (!areEqual(prevLayout, nextLayout)) {
1777
1803
  setLayout(nextLayout);
1778
- committedValuesRef.current.layout = nextLayout;
1804
+ eagerValuesRef.current.layout = nextLayout;
1779
1805
  if (onLayout) {
1780
1806
  onLayout(nextLayout.map(sizePercentage => ({
1781
1807
  sizePercentage,