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.
@@ -693,6 +693,7 @@ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
693
693
 
694
694
  function useWindowSplitterPanelGroupBehavior({
695
695
  committedValuesRef,
696
+ eagerValuesRef,
696
697
  groupId,
697
698
  layout,
698
699
  panelDataArray,
@@ -745,7 +746,7 @@ function useWindowSplitterPanelGroupBehavior({
745
746
  useEffect(() => {
746
747
  const {
747
748
  panelDataArray
748
- } = committedValuesRef.current;
749
+ } = eagerValuesRef.current;
749
750
  const groupElement = getPanelGroupElement(groupId);
750
751
  assert(groupElement != null, `No group found for id "${groupId}"`);
751
752
  const handles = getResizeHandleElementsForGroup(groupId);
@@ -803,7 +804,7 @@ function useWindowSplitterPanelGroupBehavior({
803
804
  return () => {
804
805
  cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
805
806
  };
806
- }, [committedValuesRef, groupId, layout, panelDataArray, setLayout]);
807
+ }, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
807
808
  }
808
809
 
809
810
  function areEqual(arrayA, arrayB) {
@@ -1345,11 +1346,13 @@ function PanelGroupWithForwardedRef({
1345
1346
  id: groupId,
1346
1347
  keyboardResizeByPercentage,
1347
1348
  keyboardResizeByPixels,
1348
- layout,
1349
1349
  onLayout,
1350
- panelDataArray: [],
1351
1350
  storage
1352
1351
  });
1352
+ const eagerValuesRef = useRef({
1353
+ layout,
1354
+ panelDataArray: []
1355
+ });
1353
1356
  const devWarningsRef = useRef({
1354
1357
  didLogIdAndOrderWarning: false,
1355
1358
  didLogPanelConstraintsWarning: false,
@@ -1359,9 +1362,11 @@ function PanelGroupWithForwardedRef({
1359
1362
  getId: () => committedValuesRef.current.id,
1360
1363
  getLayout: () => {
1361
1364
  const {
1362
- id: groupId,
1363
- layout
1365
+ id: groupId
1364
1366
  } = committedValuesRef.current;
1367
+ const {
1368
+ layout
1369
+ } = eagerValuesRef.current;
1365
1370
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1366
1371
  return layout.map(sizePercentage => {
1367
1372
  return {
@@ -1373,10 +1378,12 @@ function PanelGroupWithForwardedRef({
1373
1378
  setLayout: mixedSizes => {
1374
1379
  const {
1375
1380
  id: groupId,
1381
+ onLayout
1382
+ } = committedValuesRef.current;
1383
+ const {
1376
1384
  layout: prevLayout,
1377
- onLayout,
1378
1385
  panelDataArray
1379
- } = committedValuesRef.current;
1386
+ } = eagerValuesRef.current;
1380
1387
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1381
1388
  const unsafeLayout = mixedSizes.map(mixedSize => getPercentageSizeFromMixedSizes(mixedSize, groupSizePixels));
1382
1389
  const safeLayout = validatePanelGroupLayout({
@@ -1386,7 +1393,7 @@ function PanelGroupWithForwardedRef({
1386
1393
  });
1387
1394
  if (!areEqual(prevLayout, safeLayout)) {
1388
1395
  setLayout(safeLayout);
1389
- committedValuesRef.current.layout = safeLayout;
1396
+ eagerValuesRef.current.layout = safeLayout;
1390
1397
  if (onLayout) {
1391
1398
  onLayout(safeLayout.map(sizePercentage => ({
1392
1399
  sizePercentage,
@@ -1411,15 +1418,16 @@ function PanelGroupWithForwardedRef({
1411
1418
 
1412
1419
  useWindowSplitterPanelGroupBehavior({
1413
1420
  committedValuesRef,
1421
+ eagerValuesRef,
1414
1422
  groupId,
1415
1423
  layout,
1416
- panelDataArray: committedValuesRef.current.panelDataArray,
1424
+ panelDataArray: eagerValuesRef.current.panelDataArray,
1417
1425
  setLayout
1418
1426
  });
1419
1427
  useEffect(() => {
1420
1428
  const {
1421
1429
  panelDataArray
1422
- } = committedValuesRef.current;
1430
+ } = eagerValuesRef.current;
1423
1431
 
1424
1432
  // If this panel has been configured to persist sizing information, save sizes to local storage.
1425
1433
  if (autoSaveId) {
@@ -1436,8 +1444,9 @@ function PanelGroupWithForwardedRef({
1436
1444
  }, [autoSaveId, layout, storage]);
1437
1445
  useIsomorphicLayoutEffect(() => {
1438
1446
  const {
1447
+ layout: prevLayout,
1439
1448
  panelDataArray
1440
- } = committedValuesRef.current;
1449
+ } = eagerValuesRef.current;
1441
1450
  const constraints = panelDataArray.map(({
1442
1451
  constraints
1443
1452
  }) => constraints);
@@ -1451,7 +1460,6 @@ function PanelGroupWithForwardedRef({
1451
1460
  const resizeObserver = new ResizeObserver(() => {
1452
1461
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1453
1462
  const {
1454
- layout: prevLayout,
1455
1463
  onLayout
1456
1464
  } = committedValuesRef.current;
1457
1465
  const nextLayout = validatePanelGroupLayout({
@@ -1461,7 +1469,7 @@ function PanelGroupWithForwardedRef({
1461
1469
  });
1462
1470
  if (!areEqual(prevLayout, nextLayout)) {
1463
1471
  setLayout(nextLayout);
1464
- committedValuesRef.current.layout = nextLayout;
1472
+ eagerValuesRef.current.layout = nextLayout;
1465
1473
  if (onLayout) {
1466
1474
  onLayout(nextLayout.map(sizePercentage => ({
1467
1475
  sizePercentage,
@@ -1483,7 +1491,7 @@ function PanelGroupWithForwardedRef({
1483
1491
  {
1484
1492
  const {
1485
1493
  panelDataArray
1486
- } = committedValuesRef.current;
1494
+ } = eagerValuesRef.current;
1487
1495
  const {
1488
1496
  didLogIdAndOrderWarning,
1489
1497
  didLogPanelConstraintsWarning,
@@ -1526,11 +1534,13 @@ function PanelGroupWithForwardedRef({
1526
1534
 
1527
1535
  // External APIs are safe to memoize via committed values ref
1528
1536
  const collapsePanel = useCallback(panelData => {
1537
+ const {
1538
+ onLayout
1539
+ } = committedValuesRef.current;
1529
1540
  const {
1530
1541
  layout: prevLayout,
1531
- onLayout,
1532
1542
  panelDataArray
1533
- } = committedValuesRef.current;
1543
+ } = eagerValuesRef.current;
1534
1544
  if (panelData.constraints.collapsible) {
1535
1545
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1536
1546
  const {
@@ -1555,7 +1565,7 @@ function PanelGroupWithForwardedRef({
1555
1565
  });
1556
1566
  if (!compareLayouts(prevLayout, nextLayout)) {
1557
1567
  setLayout(nextLayout);
1558
- committedValuesRef.current.layout = nextLayout;
1568
+ eagerValuesRef.current.layout = nextLayout;
1559
1569
  if (onLayout) {
1560
1570
  onLayout(nextLayout.map(sizePercentage => ({
1561
1571
  sizePercentage,
@@ -1570,11 +1580,13 @@ function PanelGroupWithForwardedRef({
1570
1580
 
1571
1581
  // External APIs are safe to memoize via committed values ref
1572
1582
  const expandPanel = useCallback(panelData => {
1583
+ const {
1584
+ onLayout
1585
+ } = committedValuesRef.current;
1573
1586
  const {
1574
1587
  layout: prevLayout,
1575
- onLayout,
1576
1588
  panelDataArray
1577
- } = committedValuesRef.current;
1589
+ } = eagerValuesRef.current;
1578
1590
  if (panelData.constraints.collapsible) {
1579
1591
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1580
1592
  const {
@@ -1600,7 +1612,7 @@ function PanelGroupWithForwardedRef({
1600
1612
  });
1601
1613
  if (!compareLayouts(prevLayout, nextLayout)) {
1602
1614
  setLayout(nextLayout);
1603
- committedValuesRef.current.layout = nextLayout;
1615
+ eagerValuesRef.current.layout = nextLayout;
1604
1616
  if (onLayout) {
1605
1617
  onLayout(nextLayout.map(sizePercentage => ({
1606
1618
  sizePercentage,
@@ -1618,7 +1630,7 @@ function PanelGroupWithForwardedRef({
1618
1630
  const {
1619
1631
  layout,
1620
1632
  panelDataArray
1621
- } = committedValuesRef.current;
1633
+ } = eagerValuesRef.current;
1622
1634
  const {
1623
1635
  panelSizePercentage,
1624
1636
  panelSizePixels
@@ -1633,7 +1645,7 @@ function PanelGroupWithForwardedRef({
1633
1645
  const getPanelStyle = useCallback(panelData => {
1634
1646
  const {
1635
1647
  panelDataArray
1636
- } = committedValuesRef.current;
1648
+ } = eagerValuesRef.current;
1637
1649
  const panelIndex = panelDataArray.indexOf(panelData);
1638
1650
  return computePanelFlexBoxStyle({
1639
1651
  dragState,
@@ -1648,7 +1660,7 @@ function PanelGroupWithForwardedRef({
1648
1660
  const {
1649
1661
  layout,
1650
1662
  panelDataArray
1651
- } = committedValuesRef.current;
1663
+ } = eagerValuesRef.current;
1652
1664
  const {
1653
1665
  collapsedSizePercentage,
1654
1666
  collapsible,
@@ -1662,7 +1674,7 @@ function PanelGroupWithForwardedRef({
1662
1674
  const {
1663
1675
  layout,
1664
1676
  panelDataArray
1665
- } = committedValuesRef.current;
1677
+ } = eagerValuesRef.current;
1666
1678
  const {
1667
1679
  collapsedSizePercentage,
1668
1680
  collapsible,
@@ -1674,11 +1686,13 @@ function PanelGroupWithForwardedRef({
1674
1686
  const {
1675
1687
  autoSaveId,
1676
1688
  id: groupId,
1677
- layout: prevLayout,
1678
1689
  onLayout,
1679
- panelDataArray,
1680
1690
  storage
1681
1691
  } = committedValuesRef.current;
1692
+ const {
1693
+ layout: prevLayout,
1694
+ panelDataArray
1695
+ } = eagerValuesRef.current;
1682
1696
  panelDataArray.push(panelData);
1683
1697
  panelDataArray.sort((panelA, panelB) => {
1684
1698
  const orderA = panelA.order;
@@ -1730,9 +1744,13 @@ function PanelGroupWithForwardedRef({
1730
1744
  layout: unsafeLayout,
1731
1745
  panelConstraints: panelDataArray.map(panelData => panelData.constraints)
1732
1746
  });
1747
+
1748
+ // Offscreen mode makes this a bit weird;
1749
+ // Panels unregister when hidden and re-register when shown again,
1750
+ // but the overall layout doesn't change between these two cases.
1751
+ setLayout(nextLayout);
1752
+ eagerValuesRef.current.layout = nextLayout;
1733
1753
  if (!areEqual(prevLayout, nextLayout)) {
1734
- setLayout(nextLayout);
1735
- committedValuesRef.current.layout = nextLayout;
1736
1754
  if (onLayout) {
1737
1755
  onLayout(nextLayout.map(sizePercentage => ({
1738
1756
  sizePercentage,
@@ -1751,10 +1769,12 @@ function PanelGroupWithForwardedRef({
1751
1769
  id: groupId,
1752
1770
  keyboardResizeByPercentage,
1753
1771
  keyboardResizeByPixels,
1754
- onLayout,
1755
- panelDataArray,
1756
- layout: prevLayout
1772
+ onLayout
1757
1773
  } = committedValuesRef.current;
1774
+ const {
1775
+ layout: prevLayout,
1776
+ panelDataArray
1777
+ } = eagerValuesRef.current;
1758
1778
  const {
1759
1779
  initialLayout
1760
1780
  } = dragState !== null && dragState !== void 0 ? dragState : {};
@@ -1810,7 +1830,7 @@ function PanelGroupWithForwardedRef({
1810
1830
  }
1811
1831
  if (layoutChanged) {
1812
1832
  setLayout(nextLayout);
1813
- committedValuesRef.current.layout = nextLayout;
1833
+ eagerValuesRef.current.layout = nextLayout;
1814
1834
  if (onLayout) {
1815
1835
  onLayout(nextLayout.map(sizePercentage => ({
1816
1836
  sizePercentage,
@@ -1824,11 +1844,13 @@ function PanelGroupWithForwardedRef({
1824
1844
 
1825
1845
  // External APIs are safe to memoize via committed values ref
1826
1846
  const resizePanel = useCallback((panelData, mixedSizes) => {
1847
+ const {
1848
+ onLayout
1849
+ } = committedValuesRef.current;
1827
1850
  const {
1828
1851
  layout: prevLayout,
1829
- onLayout,
1830
1852
  panelDataArray
1831
- } = committedValuesRef.current;
1853
+ } = eagerValuesRef.current;
1832
1854
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1833
1855
  const {
1834
1856
  groupSizePixels,
@@ -1848,7 +1870,7 @@ function PanelGroupWithForwardedRef({
1848
1870
  });
1849
1871
  if (!compareLayouts(prevLayout, nextLayout)) {
1850
1872
  setLayout(nextLayout);
1851
- committedValuesRef.current.layout = nextLayout;
1873
+ eagerValuesRef.current.layout = nextLayout;
1852
1874
  if (onLayout) {
1853
1875
  onLayout(nextLayout.map(sizePercentage => ({
1854
1876
  sizePercentage,
@@ -1860,9 +1882,11 @@ function PanelGroupWithForwardedRef({
1860
1882
  }, [groupId]);
1861
1883
  const startDragging = useCallback((dragHandleId, event) => {
1862
1884
  const {
1863
- direction,
1864
- layout
1885
+ direction
1865
1886
  } = committedValuesRef.current;
1887
+ const {
1888
+ layout
1889
+ } = eagerValuesRef.current;
1866
1890
  const handleElement = getResizeHandleElement(dragHandleId);
1867
1891
  const initialCursorPosition = getResizeEventCursorPosition(direction, event);
1868
1892
  setDragState({
@@ -1883,10 +1907,12 @@ function PanelGroupWithForwardedRef({
1883
1907
  const unregisterPanel = useCallback(panelData => {
1884
1908
  const {
1885
1909
  id: groupId,
1910
+ onLayout
1911
+ } = committedValuesRef.current;
1912
+ const {
1886
1913
  layout: prevLayout,
1887
- onLayout,
1888
1914
  panelDataArray
1889
- } = committedValuesRef.current;
1915
+ } = eagerValuesRef.current;
1890
1916
  const index = panelDataArray.indexOf(panelData);
1891
1917
  if (index >= 0) {
1892
1918
  panelDataArray.splice(index, 1);
@@ -1903,7 +1929,7 @@ function PanelGroupWithForwardedRef({
1903
1929
  const {
1904
1930
  pendingPanelIds
1905
1931
  } = unregisterPanelRef.current;
1906
- panelIdToLastNotifiedMixedSizesMapRef.current;
1932
+ const map = panelIdToLastNotifiedMixedSizesMapRef.current;
1907
1933
 
1908
1934
  // TRICKY
1909
1935
  // Strict effects mode
@@ -1919,7 +1945,7 @@ function PanelGroupWithForwardedRef({
1919
1945
  // When a panel is removed from the group, we should delete the most recent prev-size entry for it.
1920
1946
  // If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
1921
1947
  // Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
1922
- delete panelIdToLastNotifiedMixedSizesMapRef.current[panelData.id];
1948
+ delete map[panelData.id];
1923
1949
  }
1924
1950
  });
1925
1951
  if (!unmountDueToStrictMode) {
@@ -1944,7 +1970,7 @@ function PanelGroupWithForwardedRef({
1944
1970
  });
1945
1971
  if (!areEqual(prevLayout, nextLayout)) {
1946
1972
  setLayout(nextLayout);
1947
- committedValuesRef.current.layout = nextLayout;
1973
+ eagerValuesRef.current.layout = nextLayout;
1948
1974
  if (onLayout) {
1949
1975
  onLayout(nextLayout.map(sizePercentage => ({
1950
1976
  sizePercentage,
@@ -687,6 +687,7 @@ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
687
687
 
688
688
  function useWindowSplitterPanelGroupBehavior({
689
689
  committedValuesRef,
690
+ eagerValuesRef,
690
691
  groupId,
691
692
  layout,
692
693
  panelDataArray,
@@ -729,7 +730,7 @@ function useWindowSplitterPanelGroupBehavior({
729
730
  useEffect(() => {
730
731
  const {
731
732
  panelDataArray
732
- } = committedValuesRef.current;
733
+ } = eagerValuesRef.current;
733
734
  const groupElement = getPanelGroupElement(groupId);
734
735
  assert(groupElement != null, `No group found for id "${groupId}"`);
735
736
  const handles = getResizeHandleElementsForGroup(groupId);
@@ -787,7 +788,7 @@ function useWindowSplitterPanelGroupBehavior({
787
788
  return () => {
788
789
  cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
789
790
  };
790
- }, [committedValuesRef, groupId, layout, panelDataArray, setLayout]);
791
+ }, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
791
792
  }
792
793
 
793
794
  function areEqual(arrayA, arrayB) {
@@ -1252,11 +1253,13 @@ function PanelGroupWithForwardedRef({
1252
1253
  id: groupId,
1253
1254
  keyboardResizeByPercentage,
1254
1255
  keyboardResizeByPixels,
1255
- layout,
1256
1256
  onLayout,
1257
- panelDataArray: [],
1258
1257
  storage
1259
1258
  });
1259
+ const eagerValuesRef = useRef({
1260
+ layout,
1261
+ panelDataArray: []
1262
+ });
1260
1263
  useRef({
1261
1264
  didLogIdAndOrderWarning: false,
1262
1265
  didLogPanelConstraintsWarning: false,
@@ -1266,9 +1269,11 @@ function PanelGroupWithForwardedRef({
1266
1269
  getId: () => committedValuesRef.current.id,
1267
1270
  getLayout: () => {
1268
1271
  const {
1269
- id: groupId,
1270
- layout
1272
+ id: groupId
1271
1273
  } = committedValuesRef.current;
1274
+ const {
1275
+ layout
1276
+ } = eagerValuesRef.current;
1272
1277
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1273
1278
  return layout.map(sizePercentage => {
1274
1279
  return {
@@ -1280,10 +1285,12 @@ function PanelGroupWithForwardedRef({
1280
1285
  setLayout: mixedSizes => {
1281
1286
  const {
1282
1287
  id: groupId,
1288
+ onLayout
1289
+ } = committedValuesRef.current;
1290
+ const {
1283
1291
  layout: prevLayout,
1284
- onLayout,
1285
1292
  panelDataArray
1286
- } = committedValuesRef.current;
1293
+ } = eagerValuesRef.current;
1287
1294
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1288
1295
  const unsafeLayout = mixedSizes.map(mixedSize => getPercentageSizeFromMixedSizes(mixedSize, groupSizePixels));
1289
1296
  const safeLayout = validatePanelGroupLayout({
@@ -1293,7 +1300,7 @@ function PanelGroupWithForwardedRef({
1293
1300
  });
1294
1301
  if (!areEqual(prevLayout, safeLayout)) {
1295
1302
  setLayout(safeLayout);
1296
- committedValuesRef.current.layout = safeLayout;
1303
+ eagerValuesRef.current.layout = safeLayout;
1297
1304
  if (onLayout) {
1298
1305
  onLayout(safeLayout.map(sizePercentage => ({
1299
1306
  sizePercentage,
@@ -1318,15 +1325,16 @@ function PanelGroupWithForwardedRef({
1318
1325
 
1319
1326
  useWindowSplitterPanelGroupBehavior({
1320
1327
  committedValuesRef,
1328
+ eagerValuesRef,
1321
1329
  groupId,
1322
1330
  layout,
1323
- panelDataArray: committedValuesRef.current.panelDataArray,
1331
+ panelDataArray: eagerValuesRef.current.panelDataArray,
1324
1332
  setLayout
1325
1333
  });
1326
1334
  useEffect(() => {
1327
1335
  const {
1328
1336
  panelDataArray
1329
- } = committedValuesRef.current;
1337
+ } = eagerValuesRef.current;
1330
1338
 
1331
1339
  // If this panel has been configured to persist sizing information, save sizes to local storage.
1332
1340
  if (autoSaveId) {
@@ -1343,8 +1351,9 @@ function PanelGroupWithForwardedRef({
1343
1351
  }, [autoSaveId, layout, storage]);
1344
1352
  useIsomorphicLayoutEffect(() => {
1345
1353
  const {
1354
+ layout: prevLayout,
1346
1355
  panelDataArray
1347
- } = committedValuesRef.current;
1356
+ } = eagerValuesRef.current;
1348
1357
  const constraints = panelDataArray.map(({
1349
1358
  constraints
1350
1359
  }) => constraints);
@@ -1358,7 +1367,6 @@ function PanelGroupWithForwardedRef({
1358
1367
  const resizeObserver = new ResizeObserver(() => {
1359
1368
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1360
1369
  const {
1361
- layout: prevLayout,
1362
1370
  onLayout
1363
1371
  } = committedValuesRef.current;
1364
1372
  const nextLayout = validatePanelGroupLayout({
@@ -1368,7 +1376,7 @@ function PanelGroupWithForwardedRef({
1368
1376
  });
1369
1377
  if (!areEqual(prevLayout, nextLayout)) {
1370
1378
  setLayout(nextLayout);
1371
- committedValuesRef.current.layout = nextLayout;
1379
+ eagerValuesRef.current.layout = nextLayout;
1372
1380
  if (onLayout) {
1373
1381
  onLayout(nextLayout.map(sizePercentage => ({
1374
1382
  sizePercentage,
@@ -1391,11 +1399,13 @@ function PanelGroupWithForwardedRef({
1391
1399
 
1392
1400
  // External APIs are safe to memoize via committed values ref
1393
1401
  const collapsePanel = useCallback(panelData => {
1402
+ const {
1403
+ onLayout
1404
+ } = committedValuesRef.current;
1394
1405
  const {
1395
1406
  layout: prevLayout,
1396
- onLayout,
1397
1407
  panelDataArray
1398
- } = committedValuesRef.current;
1408
+ } = eagerValuesRef.current;
1399
1409
  if (panelData.constraints.collapsible) {
1400
1410
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1401
1411
  const {
@@ -1420,7 +1430,7 @@ function PanelGroupWithForwardedRef({
1420
1430
  });
1421
1431
  if (!compareLayouts(prevLayout, nextLayout)) {
1422
1432
  setLayout(nextLayout);
1423
- committedValuesRef.current.layout = nextLayout;
1433
+ eagerValuesRef.current.layout = nextLayout;
1424
1434
  if (onLayout) {
1425
1435
  onLayout(nextLayout.map(sizePercentage => ({
1426
1436
  sizePercentage,
@@ -1435,11 +1445,13 @@ function PanelGroupWithForwardedRef({
1435
1445
 
1436
1446
  // External APIs are safe to memoize via committed values ref
1437
1447
  const expandPanel = useCallback(panelData => {
1448
+ const {
1449
+ onLayout
1450
+ } = committedValuesRef.current;
1438
1451
  const {
1439
1452
  layout: prevLayout,
1440
- onLayout,
1441
1453
  panelDataArray
1442
- } = committedValuesRef.current;
1454
+ } = eagerValuesRef.current;
1443
1455
  if (panelData.constraints.collapsible) {
1444
1456
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1445
1457
  const {
@@ -1465,7 +1477,7 @@ function PanelGroupWithForwardedRef({
1465
1477
  });
1466
1478
  if (!compareLayouts(prevLayout, nextLayout)) {
1467
1479
  setLayout(nextLayout);
1468
- committedValuesRef.current.layout = nextLayout;
1480
+ eagerValuesRef.current.layout = nextLayout;
1469
1481
  if (onLayout) {
1470
1482
  onLayout(nextLayout.map(sizePercentage => ({
1471
1483
  sizePercentage,
@@ -1483,7 +1495,7 @@ function PanelGroupWithForwardedRef({
1483
1495
  const {
1484
1496
  layout,
1485
1497
  panelDataArray
1486
- } = committedValuesRef.current;
1498
+ } = eagerValuesRef.current;
1487
1499
  const {
1488
1500
  panelSizePercentage,
1489
1501
  panelSizePixels
@@ -1498,7 +1510,7 @@ function PanelGroupWithForwardedRef({
1498
1510
  const getPanelStyle = useCallback(panelData => {
1499
1511
  const {
1500
1512
  panelDataArray
1501
- } = committedValuesRef.current;
1513
+ } = eagerValuesRef.current;
1502
1514
  const panelIndex = panelDataArray.indexOf(panelData);
1503
1515
  return computePanelFlexBoxStyle({
1504
1516
  dragState,
@@ -1513,7 +1525,7 @@ function PanelGroupWithForwardedRef({
1513
1525
  const {
1514
1526
  layout,
1515
1527
  panelDataArray
1516
- } = committedValuesRef.current;
1528
+ } = eagerValuesRef.current;
1517
1529
  const {
1518
1530
  collapsedSizePercentage,
1519
1531
  collapsible,
@@ -1527,7 +1539,7 @@ function PanelGroupWithForwardedRef({
1527
1539
  const {
1528
1540
  layout,
1529
1541
  panelDataArray
1530
- } = committedValuesRef.current;
1542
+ } = eagerValuesRef.current;
1531
1543
  const {
1532
1544
  collapsedSizePercentage,
1533
1545
  collapsible,
@@ -1539,11 +1551,13 @@ function PanelGroupWithForwardedRef({
1539
1551
  const {
1540
1552
  autoSaveId,
1541
1553
  id: groupId,
1542
- layout: prevLayout,
1543
1554
  onLayout,
1544
- panelDataArray,
1545
1555
  storage
1546
1556
  } = committedValuesRef.current;
1557
+ const {
1558
+ layout: prevLayout,
1559
+ panelDataArray
1560
+ } = eagerValuesRef.current;
1547
1561
  panelDataArray.push(panelData);
1548
1562
  panelDataArray.sort((panelA, panelB) => {
1549
1563
  const orderA = panelA.order;
@@ -1595,9 +1609,13 @@ function PanelGroupWithForwardedRef({
1595
1609
  layout: unsafeLayout,
1596
1610
  panelConstraints: panelDataArray.map(panelData => panelData.constraints)
1597
1611
  });
1612
+
1613
+ // Offscreen mode makes this a bit weird;
1614
+ // Panels unregister when hidden and re-register when shown again,
1615
+ // but the overall layout doesn't change between these two cases.
1616
+ setLayout(nextLayout);
1617
+ eagerValuesRef.current.layout = nextLayout;
1598
1618
  if (!areEqual(prevLayout, nextLayout)) {
1599
- setLayout(nextLayout);
1600
- committedValuesRef.current.layout = nextLayout;
1601
1619
  if (onLayout) {
1602
1620
  onLayout(nextLayout.map(sizePercentage => ({
1603
1621
  sizePercentage,
@@ -1616,10 +1634,12 @@ function PanelGroupWithForwardedRef({
1616
1634
  id: groupId,
1617
1635
  keyboardResizeByPercentage,
1618
1636
  keyboardResizeByPixels,
1619
- onLayout,
1620
- panelDataArray,
1621
- layout: prevLayout
1637
+ onLayout
1622
1638
  } = committedValuesRef.current;
1639
+ const {
1640
+ layout: prevLayout,
1641
+ panelDataArray
1642
+ } = eagerValuesRef.current;
1623
1643
  const {
1624
1644
  initialLayout
1625
1645
  } = dragState !== null && dragState !== void 0 ? dragState : {};
@@ -1675,7 +1695,7 @@ function PanelGroupWithForwardedRef({
1675
1695
  }
1676
1696
  if (layoutChanged) {
1677
1697
  setLayout(nextLayout);
1678
- committedValuesRef.current.layout = nextLayout;
1698
+ eagerValuesRef.current.layout = nextLayout;
1679
1699
  if (onLayout) {
1680
1700
  onLayout(nextLayout.map(sizePercentage => ({
1681
1701
  sizePercentage,
@@ -1689,11 +1709,13 @@ function PanelGroupWithForwardedRef({
1689
1709
 
1690
1710
  // External APIs are safe to memoize via committed values ref
1691
1711
  const resizePanel = useCallback((panelData, mixedSizes) => {
1712
+ const {
1713
+ onLayout
1714
+ } = committedValuesRef.current;
1692
1715
  const {
1693
1716
  layout: prevLayout,
1694
- onLayout,
1695
1717
  panelDataArray
1696
- } = committedValuesRef.current;
1718
+ } = eagerValuesRef.current;
1697
1719
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1698
1720
  const {
1699
1721
  groupSizePixels,
@@ -1713,7 +1735,7 @@ function PanelGroupWithForwardedRef({
1713
1735
  });
1714
1736
  if (!compareLayouts(prevLayout, nextLayout)) {
1715
1737
  setLayout(nextLayout);
1716
- committedValuesRef.current.layout = nextLayout;
1738
+ eagerValuesRef.current.layout = nextLayout;
1717
1739
  if (onLayout) {
1718
1740
  onLayout(nextLayout.map(sizePercentage => ({
1719
1741
  sizePercentage,
@@ -1725,9 +1747,11 @@ function PanelGroupWithForwardedRef({
1725
1747
  }, [groupId]);
1726
1748
  const startDragging = useCallback((dragHandleId, event) => {
1727
1749
  const {
1728
- direction,
1729
- layout
1750
+ direction
1730
1751
  } = committedValuesRef.current;
1752
+ const {
1753
+ layout
1754
+ } = eagerValuesRef.current;
1731
1755
  const handleElement = getResizeHandleElement(dragHandleId);
1732
1756
  const initialCursorPosition = getResizeEventCursorPosition(direction, event);
1733
1757
  setDragState({
@@ -1748,10 +1772,12 @@ function PanelGroupWithForwardedRef({
1748
1772
  const unregisterPanel = useCallback(panelData => {
1749
1773
  const {
1750
1774
  id: groupId,
1775
+ onLayout
1776
+ } = committedValuesRef.current;
1777
+ const {
1751
1778
  layout: prevLayout,
1752
- onLayout,
1753
1779
  panelDataArray
1754
- } = committedValuesRef.current;
1780
+ } = eagerValuesRef.current;
1755
1781
  const index = panelDataArray.indexOf(panelData);
1756
1782
  if (index >= 0) {
1757
1783
  panelDataArray.splice(index, 1);
@@ -1768,7 +1794,7 @@ function PanelGroupWithForwardedRef({
1768
1794
  const {
1769
1795
  pendingPanelIds
1770
1796
  } = unregisterPanelRef.current;
1771
- panelIdToLastNotifiedMixedSizesMapRef.current;
1797
+ const map = panelIdToLastNotifiedMixedSizesMapRef.current;
1772
1798
 
1773
1799
  // TRICKY
1774
1800
  // Strict effects mode
@@ -1784,7 +1810,7 @@ function PanelGroupWithForwardedRef({
1784
1810
  // When a panel is removed from the group, we should delete the most recent prev-size entry for it.
1785
1811
  // If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
1786
1812
  // Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
1787
- delete panelIdToLastNotifiedMixedSizesMapRef.current[panelData.id];
1813
+ delete map[panelData.id];
1788
1814
  }
1789
1815
  });
1790
1816
  if (!unmountDueToStrictMode) {
@@ -1809,7 +1835,7 @@ function PanelGroupWithForwardedRef({
1809
1835
  });
1810
1836
  if (!areEqual(prevLayout, nextLayout)) {
1811
1837
  setLayout(nextLayout);
1812
- committedValuesRef.current.layout = nextLayout;
1838
+ eagerValuesRef.current.layout = nextLayout;
1813
1839
  if (onLayout) {
1814
1840
  onLayout(nextLayout.map(sizePercentage => ({
1815
1841
  sizePercentage,