@mui/x-data-grid 6.19.10 → 6.19.11

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 CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 6.19.11
7
+
8
+ _Apr 18, 2024_
9
+
10
+ We'd like to offer a big thanks to the 1 contributor who made this release possible. Here are some highlights ✨:
11
+
12
+ - 🐞 Bugfixes
13
+
14
+ ### Data Grid
15
+
16
+ #### `@mui/x-data-grid@6.19.11`
17
+
18
+ - [DataGrid] Fix virtualization memory leak (#12812) @romgrk
19
+
20
+ #### `@mui/x-data-grid-pro@6.19.11` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
21
+
22
+ Same changes as in `@mui/x-data-grid@6.19.11`.
23
+
24
+ #### `@mui/x-data-grid-premium@6.19.11` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
25
+
26
+ Same changes as in `@mui/x-data-grid-pro@6.19.11`.
27
+
6
28
  ## 6.19.10
7
29
 
8
30
  _Apr 12, 2024_
@@ -63,7 +63,6 @@ const MEMOIZE_OPTIONS = {
63
63
  maxSize: 3
64
64
  };
65
65
  export const useGridVirtualScroller = props => {
66
- var _currentPage$range3, _currentPage$range4;
67
66
  const apiRef = useGridPrivateApiContext();
68
67
  const rootProps = useGridRootProps();
69
68
  const visibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
@@ -134,27 +133,6 @@ export const useGridVirtualScroller = props => {
134
133
  }
135
134
  return -1;
136
135
  }, [cellFocus, visibleColumns]);
137
- const getNearestIndexToRender = React.useCallback(offset => {
138
- var _currentPage$range, _currentPage$range2;
139
- const lastMeasuredIndexRelativeToAllRows = apiRef.current.getLastMeasuredRowIndex();
140
- let allRowsMeasured = lastMeasuredIndexRelativeToAllRows === Infinity;
141
- if ((_currentPage$range = currentPage.range) != null && _currentPage$range.lastRowIndex && !allRowsMeasured) {
142
- // Check if all rows in this page are already measured
143
- allRowsMeasured = lastMeasuredIndexRelativeToAllRows >= currentPage.range.lastRowIndex;
144
- }
145
- const lastMeasuredIndexRelativeToCurrentPage = clamp(lastMeasuredIndexRelativeToAllRows - (((_currentPage$range2 = currentPage.range) == null ? void 0 : _currentPage$range2.firstRowIndex) || 0), 0, rowsMeta.positions.length);
146
- if (allRowsMeasured || rowsMeta.positions[lastMeasuredIndexRelativeToCurrentPage] >= offset) {
147
- // If all rows were measured (when no row has "auto" as height) or all rows before the offset
148
- // were measured, then use a binary search because it's faster.
149
- return binarySearch(offset, rowsMeta.positions);
150
- }
151
-
152
- // Otherwise, use an exponential search.
153
- // If rows have "auto" as height, their positions will be based on estimated heights.
154
- // In this case, we can skip several steps until we find a position higher than the offset.
155
- // Inspired by https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/utils/CellSizeAndPositionManager.js
156
- return exponentialSearch(offset, rowsMeta.positions, lastMeasuredIndexRelativeToCurrentPage);
157
- }, [apiRef, (_currentPage$range3 = currentPage.range) == null ? void 0 : _currentPage$range3.firstRowIndex, (_currentPage$range4 = currentPage.range) == null ? void 0 : _currentPage$range4.lastRowIndex, rowsMeta.positions]);
158
136
  const computeRenderContext = React.useCallback(() => {
159
137
  if (!enabled) {
160
138
  return {
@@ -171,8 +149,8 @@ export const useGridVirtualScroller = props => {
171
149
 
172
150
  // Clamp the value because the search may return an index out of bounds.
173
151
  // In the last index, this is not needed because Array.slice doesn't include it.
174
- const firstRowIndex = Math.min(getNearestIndexToRender(top), rowsMeta.positions.length - 1);
175
- const lastRowIndex = rootProps.autoHeight ? firstRowIndex + currentPage.rows.length : getNearestIndexToRender(top + containerDimensions.height);
152
+ const firstRowIndex = Math.min(getNearestIndexToRender(apiRef, currentPage, rowsMeta, top), rowsMeta.positions.length - 1);
153
+ const lastRowIndex = rootProps.autoHeight ? firstRowIndex + currentPage.rows.length : getNearestIndexToRender(apiRef, currentPage, rowsMeta, top + containerDimensions.height);
176
154
  let firstColumnIndex = 0;
177
155
  let lastColumnIndex = columnPositions.length;
178
156
  if (enabledForColumns) {
@@ -199,7 +177,7 @@ export const useGridVirtualScroller = props => {
199
177
  firstColumnIndex,
200
178
  lastColumnIndex
201
179
  };
202
- }, [enabled, enabledForColumns, getNearestIndexToRender, rowsMeta.positions.length, rootProps.autoHeight, rootProps.rowBuffer, currentPage.rows, columnPositions, visibleColumns.length, apiRef, containerDimensions]);
180
+ }, [enabled, enabledForColumns, rowsMeta, rootProps.autoHeight, rootProps.rowBuffer, currentPage, columnPositions, visibleColumns.length, apiRef, containerDimensions]);
203
181
  useEnhancedEffect(() => {
204
182
  if (enabled) {
205
183
  // TODO a scroll reset should not be necessary
@@ -470,7 +448,7 @@ export const useGridVirtualScroller = props => {
470
448
  const rows = [];
471
449
  let isRowWithFocusedCellRendered = false;
472
450
  for (let i = 0; i < renderedRows.length; i += 1) {
473
- var _currentPage$range5;
451
+ var _currentPage$range;
474
452
  const {
475
453
  id,
476
454
  model
@@ -504,7 +482,7 @@ export const useGridVirtualScroller = props => {
504
482
  const style = _extends({}, rowStyle, rootRowStyle);
505
483
  rowStyleCache.current[id] = style;
506
484
  }
507
- let index = rowIndexOffset + ((currentPage == null || (_currentPage$range5 = currentPage.range) == null ? void 0 : _currentPage$range5.firstRowIndex) || 0) + firstRowToRender + i;
485
+ let index = rowIndexOffset + ((currentPage == null || (_currentPage$range = currentPage.range) == null ? void 0 : _currentPage$range.firstRowIndex) || 0) + firstRowToRender + i;
508
486
  if (isRowWithFocusedCellNotInRange && (cellFocus == null ? void 0 : cellFocus.id) === id) {
509
487
  index = indexOfRowWithFocusedCell;
510
488
  isRowWithFocusedCellRendered = true;
@@ -597,4 +575,25 @@ export const useGridVirtualScroller = props => {
597
575
  role: 'rowgroup'
598
576
  })
599
577
  };
600
- };
578
+ };
579
+ function getNearestIndexToRender(apiRef, currentPage, rowsMeta, offset) {
580
+ var _currentPage$range2, _currentPage$range3;
581
+ const lastMeasuredIndexRelativeToAllRows = apiRef.current.getLastMeasuredRowIndex();
582
+ let allRowsMeasured = lastMeasuredIndexRelativeToAllRows === Infinity;
583
+ if ((_currentPage$range2 = currentPage.range) != null && _currentPage$range2.lastRowIndex && !allRowsMeasured) {
584
+ // Check if all rows in this page are already measured
585
+ allRowsMeasured = lastMeasuredIndexRelativeToAllRows >= currentPage.range.lastRowIndex;
586
+ }
587
+ const lastMeasuredIndexRelativeToCurrentPage = clamp(lastMeasuredIndexRelativeToAllRows - (((_currentPage$range3 = currentPage.range) == null ? void 0 : _currentPage$range3.firstRowIndex) || 0), 0, rowsMeta.positions.length);
588
+ if (allRowsMeasured || rowsMeta.positions[lastMeasuredIndexRelativeToCurrentPage] >= offset) {
589
+ // If all rows were measured (when no row has "auto" as height) or all rows before the offset
590
+ // were measured, then use a binary search because it's faster.
591
+ return binarySearch(offset, rowsMeta.positions);
592
+ }
593
+
594
+ // Otherwise, use an exponential search.
595
+ // If rows have "auto" as height, their positions will be based on estimated heights.
596
+ // In this case, we can skip several steps until we find a position higher than the offset.
597
+ // Inspired by https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/utils/CellSizeAndPositionManager.js
598
+ return exponentialSearch(offset, rowsMeta.positions, lastMeasuredIndexRelativeToCurrentPage);
599
+ }
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v6.19.10
2
+ * @mui/x-data-grid v6.19.11
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -66,7 +66,6 @@ var MEMOIZE_OPTIONS = {
66
66
  maxSize: 3
67
67
  };
68
68
  export var useGridVirtualScroller = function useGridVirtualScroller(props) {
69
- var _currentPage$range3, _currentPage$range4;
70
69
  var apiRef = useGridPrivateApiContext();
71
70
  var rootProps = useGridRootProps();
72
71
  var visibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
@@ -148,27 +147,6 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
148
147
  }
149
148
  return -1;
150
149
  }, [cellFocus, visibleColumns]);
151
- var getNearestIndexToRender = React.useCallback(function (offset) {
152
- var _currentPage$range, _currentPage$range2;
153
- var lastMeasuredIndexRelativeToAllRows = apiRef.current.getLastMeasuredRowIndex();
154
- var allRowsMeasured = lastMeasuredIndexRelativeToAllRows === Infinity;
155
- if ((_currentPage$range = currentPage.range) != null && _currentPage$range.lastRowIndex && !allRowsMeasured) {
156
- // Check if all rows in this page are already measured
157
- allRowsMeasured = lastMeasuredIndexRelativeToAllRows >= currentPage.range.lastRowIndex;
158
- }
159
- var lastMeasuredIndexRelativeToCurrentPage = clamp(lastMeasuredIndexRelativeToAllRows - (((_currentPage$range2 = currentPage.range) == null ? void 0 : _currentPage$range2.firstRowIndex) || 0), 0, rowsMeta.positions.length);
160
- if (allRowsMeasured || rowsMeta.positions[lastMeasuredIndexRelativeToCurrentPage] >= offset) {
161
- // If all rows were measured (when no row has "auto" as height) or all rows before the offset
162
- // were measured, then use a binary search because it's faster.
163
- return binarySearch(offset, rowsMeta.positions);
164
- }
165
-
166
- // Otherwise, use an exponential search.
167
- // If rows have "auto" as height, their positions will be based on estimated heights.
168
- // In this case, we can skip several steps until we find a position higher than the offset.
169
- // Inspired by https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/utils/CellSizeAndPositionManager.js
170
- return exponentialSearch(offset, rowsMeta.positions, lastMeasuredIndexRelativeToCurrentPage);
171
- }, [apiRef, (_currentPage$range3 = currentPage.range) == null ? void 0 : _currentPage$range3.firstRowIndex, (_currentPage$range4 = currentPage.range) == null ? void 0 : _currentPage$range4.lastRowIndex, rowsMeta.positions]);
172
150
  var computeRenderContext = React.useCallback(function () {
173
151
  if (!enabled) {
174
152
  return {
@@ -184,8 +162,8 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
184
162
 
185
163
  // Clamp the value because the search may return an index out of bounds.
186
164
  // In the last index, this is not needed because Array.slice doesn't include it.
187
- var firstRowIndex = Math.min(getNearestIndexToRender(top), rowsMeta.positions.length - 1);
188
- var lastRowIndex = rootProps.autoHeight ? firstRowIndex + currentPage.rows.length : getNearestIndexToRender(top + containerDimensions.height);
165
+ var firstRowIndex = Math.min(getNearestIndexToRender(apiRef, currentPage, rowsMeta, top), rowsMeta.positions.length - 1);
166
+ var lastRowIndex = rootProps.autoHeight ? firstRowIndex + currentPage.rows.length : getNearestIndexToRender(apiRef, currentPage, rowsMeta, top + containerDimensions.height);
189
167
  var firstColumnIndex = 0;
190
168
  var lastColumnIndex = columnPositions.length;
191
169
  if (enabledForColumns) {
@@ -215,7 +193,7 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
215
193
  firstColumnIndex: firstColumnIndex,
216
194
  lastColumnIndex: lastColumnIndex
217
195
  };
218
- }, [enabled, enabledForColumns, getNearestIndexToRender, rowsMeta.positions.length, rootProps.autoHeight, rootProps.rowBuffer, currentPage.rows, columnPositions, visibleColumns.length, apiRef, containerDimensions]);
196
+ }, [enabled, enabledForColumns, rowsMeta, rootProps.autoHeight, rootProps.rowBuffer, currentPage, columnPositions, visibleColumns.length, apiRef, containerDimensions]);
219
197
  useEnhancedEffect(function () {
220
198
  if (enabled) {
221
199
  // TODO a scroll reset should not be necessary
@@ -503,7 +481,7 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
503
481
  var rows = [];
504
482
  var isRowWithFocusedCellRendered = false;
505
483
  for (var _i = 0; _i < renderedRows.length; _i += 1) {
506
- var _currentPage$range5;
484
+ var _currentPage$range;
507
485
  var _renderedRows$_i = renderedRows[_i],
508
486
  _id = _renderedRows$_i.id,
509
487
  _model = _renderedRows$_i.model;
@@ -534,7 +512,7 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
534
512
  var style = _extends({}, rowStyle, rootRowStyle);
535
513
  rowStyleCache.current[_id] = style;
536
514
  }
537
- var index = rowIndexOffset + ((currentPage == null || (_currentPage$range5 = currentPage.range) == null ? void 0 : _currentPage$range5.firstRowIndex) || 0) + firstRowToRender + _i;
515
+ var index = rowIndexOffset + ((currentPage == null || (_currentPage$range = currentPage.range) == null ? void 0 : _currentPage$range.firstRowIndex) || 0) + firstRowToRender + _i;
538
516
  if (isRowWithFocusedCellNotInRange && (cellFocus == null ? void 0 : cellFocus.id) === _id) {
539
517
  index = indexOfRowWithFocusedCell;
540
518
  isRowWithFocusedCellRendered = true;
@@ -634,4 +612,25 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
634
612
  };
635
613
  }
636
614
  };
637
- };
615
+ };
616
+ function getNearestIndexToRender(apiRef, currentPage, rowsMeta, offset) {
617
+ var _currentPage$range2, _currentPage$range3;
618
+ var lastMeasuredIndexRelativeToAllRows = apiRef.current.getLastMeasuredRowIndex();
619
+ var allRowsMeasured = lastMeasuredIndexRelativeToAllRows === Infinity;
620
+ if ((_currentPage$range2 = currentPage.range) != null && _currentPage$range2.lastRowIndex && !allRowsMeasured) {
621
+ // Check if all rows in this page are already measured
622
+ allRowsMeasured = lastMeasuredIndexRelativeToAllRows >= currentPage.range.lastRowIndex;
623
+ }
624
+ var lastMeasuredIndexRelativeToCurrentPage = clamp(lastMeasuredIndexRelativeToAllRows - (((_currentPage$range3 = currentPage.range) == null ? void 0 : _currentPage$range3.firstRowIndex) || 0), 0, rowsMeta.positions.length);
625
+ if (allRowsMeasured || rowsMeta.positions[lastMeasuredIndexRelativeToCurrentPage] >= offset) {
626
+ // If all rows were measured (when no row has "auto" as height) or all rows before the offset
627
+ // were measured, then use a binary search because it's faster.
628
+ return binarySearch(offset, rowsMeta.positions);
629
+ }
630
+
631
+ // Otherwise, use an exponential search.
632
+ // If rows have "auto" as height, their positions will be based on estimated heights.
633
+ // In this case, we can skip several steps until we find a position higher than the offset.
634
+ // Inspired by https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/utils/CellSizeAndPositionManager.js
635
+ return exponentialSearch(offset, rowsMeta.positions, lastMeasuredIndexRelativeToCurrentPage);
636
+ }
package/legacy/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v6.19.10
2
+ * @mui/x-data-grid v6.19.11
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -133,26 +133,6 @@ export const useGridVirtualScroller = props => {
133
133
  }
134
134
  return -1;
135
135
  }, [cellFocus, visibleColumns]);
136
- const getNearestIndexToRender = React.useCallback(offset => {
137
- const lastMeasuredIndexRelativeToAllRows = apiRef.current.getLastMeasuredRowIndex();
138
- let allRowsMeasured = lastMeasuredIndexRelativeToAllRows === Infinity;
139
- if (currentPage.range?.lastRowIndex && !allRowsMeasured) {
140
- // Check if all rows in this page are already measured
141
- allRowsMeasured = lastMeasuredIndexRelativeToAllRows >= currentPage.range.lastRowIndex;
142
- }
143
- const lastMeasuredIndexRelativeToCurrentPage = clamp(lastMeasuredIndexRelativeToAllRows - (currentPage.range?.firstRowIndex || 0), 0, rowsMeta.positions.length);
144
- if (allRowsMeasured || rowsMeta.positions[lastMeasuredIndexRelativeToCurrentPage] >= offset) {
145
- // If all rows were measured (when no row has "auto" as height) or all rows before the offset
146
- // were measured, then use a binary search because it's faster.
147
- return binarySearch(offset, rowsMeta.positions);
148
- }
149
-
150
- // Otherwise, use an exponential search.
151
- // If rows have "auto" as height, their positions will be based on estimated heights.
152
- // In this case, we can skip several steps until we find a position higher than the offset.
153
- // Inspired by https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/utils/CellSizeAndPositionManager.js
154
- return exponentialSearch(offset, rowsMeta.positions, lastMeasuredIndexRelativeToCurrentPage);
155
- }, [apiRef, currentPage.range?.firstRowIndex, currentPage.range?.lastRowIndex, rowsMeta.positions]);
156
136
  const computeRenderContext = React.useCallback(() => {
157
137
  if (!enabled) {
158
138
  return {
@@ -169,8 +149,8 @@ export const useGridVirtualScroller = props => {
169
149
 
170
150
  // Clamp the value because the search may return an index out of bounds.
171
151
  // In the last index, this is not needed because Array.slice doesn't include it.
172
- const firstRowIndex = Math.min(getNearestIndexToRender(top), rowsMeta.positions.length - 1);
173
- const lastRowIndex = rootProps.autoHeight ? firstRowIndex + currentPage.rows.length : getNearestIndexToRender(top + containerDimensions.height);
152
+ const firstRowIndex = Math.min(getNearestIndexToRender(apiRef, currentPage, rowsMeta, top), rowsMeta.positions.length - 1);
153
+ const lastRowIndex = rootProps.autoHeight ? firstRowIndex + currentPage.rows.length : getNearestIndexToRender(apiRef, currentPage, rowsMeta, top + containerDimensions.height);
174
154
  let firstColumnIndex = 0;
175
155
  let lastColumnIndex = columnPositions.length;
176
156
  if (enabledForColumns) {
@@ -197,7 +177,7 @@ export const useGridVirtualScroller = props => {
197
177
  firstColumnIndex,
198
178
  lastColumnIndex
199
179
  };
200
- }, [enabled, enabledForColumns, getNearestIndexToRender, rowsMeta.positions.length, rootProps.autoHeight, rootProps.rowBuffer, currentPage.rows, columnPositions, visibleColumns.length, apiRef, containerDimensions]);
180
+ }, [enabled, enabledForColumns, rowsMeta, rootProps.autoHeight, rootProps.rowBuffer, currentPage, columnPositions, visibleColumns.length, apiRef, containerDimensions]);
201
181
  useEnhancedEffect(() => {
202
182
  if (enabled) {
203
183
  // TODO a scroll reset should not be necessary
@@ -592,4 +572,24 @@ export const useGridVirtualScroller = props => {
592
572
  role: 'rowgroup'
593
573
  })
594
574
  };
595
- };
575
+ };
576
+ function getNearestIndexToRender(apiRef, currentPage, rowsMeta, offset) {
577
+ const lastMeasuredIndexRelativeToAllRows = apiRef.current.getLastMeasuredRowIndex();
578
+ let allRowsMeasured = lastMeasuredIndexRelativeToAllRows === Infinity;
579
+ if (currentPage.range?.lastRowIndex && !allRowsMeasured) {
580
+ // Check if all rows in this page are already measured
581
+ allRowsMeasured = lastMeasuredIndexRelativeToAllRows >= currentPage.range.lastRowIndex;
582
+ }
583
+ const lastMeasuredIndexRelativeToCurrentPage = clamp(lastMeasuredIndexRelativeToAllRows - (currentPage.range?.firstRowIndex || 0), 0, rowsMeta.positions.length);
584
+ if (allRowsMeasured || rowsMeta.positions[lastMeasuredIndexRelativeToCurrentPage] >= offset) {
585
+ // If all rows were measured (when no row has "auto" as height) or all rows before the offset
586
+ // were measured, then use a binary search because it's faster.
587
+ return binarySearch(offset, rowsMeta.positions);
588
+ }
589
+
590
+ // Otherwise, use an exponential search.
591
+ // If rows have "auto" as height, their positions will be based on estimated heights.
592
+ // In this case, we can skip several steps until we find a position higher than the offset.
593
+ // Inspired by https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/utils/CellSizeAndPositionManager.js
594
+ return exponentialSearch(offset, rowsMeta.positions, lastMeasuredIndexRelativeToCurrentPage);
595
+ }
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v6.19.10
2
+ * @mui/x-data-grid v6.19.11
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -144,26 +144,6 @@ const useGridVirtualScroller = props => {
144
144
  }
145
145
  return -1;
146
146
  }, [cellFocus, visibleColumns]);
147
- const getNearestIndexToRender = React.useCallback(offset => {
148
- const lastMeasuredIndexRelativeToAllRows = apiRef.current.getLastMeasuredRowIndex();
149
- let allRowsMeasured = lastMeasuredIndexRelativeToAllRows === Infinity;
150
- if (currentPage.range?.lastRowIndex && !allRowsMeasured) {
151
- // Check if all rows in this page are already measured
152
- allRowsMeasured = lastMeasuredIndexRelativeToAllRows >= currentPage.range.lastRowIndex;
153
- }
154
- const lastMeasuredIndexRelativeToCurrentPage = (0, _utils2.clamp)(lastMeasuredIndexRelativeToAllRows - (currentPage.range?.firstRowIndex || 0), 0, rowsMeta.positions.length);
155
- if (allRowsMeasured || rowsMeta.positions[lastMeasuredIndexRelativeToCurrentPage] >= offset) {
156
- // If all rows were measured (when no row has "auto" as height) or all rows before the offset
157
- // were measured, then use a binary search because it's faster.
158
- return binarySearch(offset, rowsMeta.positions);
159
- }
160
-
161
- // Otherwise, use an exponential search.
162
- // If rows have "auto" as height, their positions will be based on estimated heights.
163
- // In this case, we can skip several steps until we find a position higher than the offset.
164
- // Inspired by https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/utils/CellSizeAndPositionManager.js
165
- return exponentialSearch(offset, rowsMeta.positions, lastMeasuredIndexRelativeToCurrentPage);
166
- }, [apiRef, currentPage.range?.firstRowIndex, currentPage.range?.lastRowIndex, rowsMeta.positions]);
167
147
  const computeRenderContext = React.useCallback(() => {
168
148
  if (!enabled) {
169
149
  return {
@@ -180,8 +160,8 @@ const useGridVirtualScroller = props => {
180
160
 
181
161
  // Clamp the value because the search may return an index out of bounds.
182
162
  // In the last index, this is not needed because Array.slice doesn't include it.
183
- const firstRowIndex = Math.min(getNearestIndexToRender(top), rowsMeta.positions.length - 1);
184
- const lastRowIndex = rootProps.autoHeight ? firstRowIndex + currentPage.rows.length : getNearestIndexToRender(top + containerDimensions.height);
163
+ const firstRowIndex = Math.min(getNearestIndexToRender(apiRef, currentPage, rowsMeta, top), rowsMeta.positions.length - 1);
164
+ const lastRowIndex = rootProps.autoHeight ? firstRowIndex + currentPage.rows.length : getNearestIndexToRender(apiRef, currentPage, rowsMeta, top + containerDimensions.height);
185
165
  let firstColumnIndex = 0;
186
166
  let lastColumnIndex = columnPositions.length;
187
167
  if (enabledForColumns) {
@@ -208,7 +188,7 @@ const useGridVirtualScroller = props => {
208
188
  firstColumnIndex,
209
189
  lastColumnIndex
210
190
  };
211
- }, [enabled, enabledForColumns, getNearestIndexToRender, rowsMeta.positions.length, rootProps.autoHeight, rootProps.rowBuffer, currentPage.rows, columnPositions, visibleColumns.length, apiRef, containerDimensions]);
191
+ }, [enabled, enabledForColumns, rowsMeta, rootProps.autoHeight, rootProps.rowBuffer, currentPage, columnPositions, visibleColumns.length, apiRef, containerDimensions]);
212
192
  (0, _utils.unstable_useEnhancedEffect)(() => {
213
193
  if (enabled) {
214
194
  // TODO a scroll reset should not be necessary
@@ -604,4 +584,24 @@ const useGridVirtualScroller = props => {
604
584
  })
605
585
  };
606
586
  };
607
- exports.useGridVirtualScroller = useGridVirtualScroller;
587
+ exports.useGridVirtualScroller = useGridVirtualScroller;
588
+ function getNearestIndexToRender(apiRef, currentPage, rowsMeta, offset) {
589
+ const lastMeasuredIndexRelativeToAllRows = apiRef.current.getLastMeasuredRowIndex();
590
+ let allRowsMeasured = lastMeasuredIndexRelativeToAllRows === Infinity;
591
+ if (currentPage.range?.lastRowIndex && !allRowsMeasured) {
592
+ // Check if all rows in this page are already measured
593
+ allRowsMeasured = lastMeasuredIndexRelativeToAllRows >= currentPage.range.lastRowIndex;
594
+ }
595
+ const lastMeasuredIndexRelativeToCurrentPage = (0, _utils2.clamp)(lastMeasuredIndexRelativeToAllRows - (currentPage.range?.firstRowIndex || 0), 0, rowsMeta.positions.length);
596
+ if (allRowsMeasured || rowsMeta.positions[lastMeasuredIndexRelativeToCurrentPage] >= offset) {
597
+ // If all rows were measured (when no row has "auto" as height) or all rows before the offset
598
+ // were measured, then use a binary search because it's faster.
599
+ return binarySearch(offset, rowsMeta.positions);
600
+ }
601
+
602
+ // Otherwise, use an exponential search.
603
+ // If rows have "auto" as height, their positions will be based on estimated heights.
604
+ // In this case, we can skip several steps until we find a position higher than the offset.
605
+ // Inspired by https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/utils/CellSizeAndPositionManager.js
606
+ return exponentialSearch(offset, rowsMeta.positions, lastMeasuredIndexRelativeToCurrentPage);
607
+ }
package/node/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v6.19.10
2
+ * @mui/x-data-grid v6.19.11
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-data-grid",
3
- "version": "6.19.10",
3
+ "version": "6.19.11",
4
4
  "description": "The community edition of the data grid component (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./node/index.js",