Scroll jumps in List with CellMeasurerCache
Do you want to request a feature or report a bug?
- BUG
What is the current behavior?
- When I try to remove two rows and add one new row instead, the scroll jumps to the bottom of the list. This bug seems to appear only when the operation is performed at the bottom of the list.

What is the expected behavior?
- Scroll stays in the current position after operation.
Which versions of React and react-virtualized, and which browser / OS are affected by this issue?
| react-virtualized | 9.21.0 |
| React | 16.2.0 |
| React DOM | 6.2.0 |
| Browser | Chrome, Firefox, Edge |
| OS | Windows 10 |
+1 having the same issue
I analize problem in source code and I think it's problem with method Grid/utils/CellSizeAndPositionManager.getTotalSize() executed by Grid/utils/updateScrollIndexHelper
Describe example
In example I removed rows with index 94 and 95, and add new Row instead (index = 94) without size in cache.
Path of algorithm after this operation
1) consequences of the add new row
- CellMeasurer analize rows, and found new row(94) and run method Grid.invalidateCellSizeAfterRender({columnIndex = 0, rowIndex = 94))
- Then execute
Grid.recomputeGridSizeand setthis._lastMeasuredIndex = index - 1 (93)inCellSizeAndPositionManager
2) consequences of the remove two rorws
// 85 line in Grid/utils/updateScrollIndexHlper.js
else if (
!hasScrollToIndex &&
cellCount > 0 &&
(size < previousSize || cellCount < previousCellsCount)
) {
// We need to ensure that the current scroll offset is still within the collection's range.
// To do this, we don't need to measure everything; CellMeasurer would perform poorly.
// Just check to make sure we're still okay.
// Only adjust the scroll position if we've scrolled below the last set of rows.
if (scrollOffset > cellSizeAndPositionManager.getTotalSize() - size) {
updateScrollIndexCallback(cellCount - 1);
}
}
- Condition of
ifis true, becausecellCount < previousCellsCount (99 < 100). - Then method
Grid/utils/CellSizeAndPositionManager.getTotalSize()inside this block of code return wrong value. Then fulfilling the below condition and reset vertical scrollOffset:
//line 94 in /Grid/utils/updateScrollIndexHelper.js
if (scrollOffset > cellSizeAndPositionManager.getTotalSize() - size) {
updateScrollIndexCallback(cellCount - 1);
}
cellSizeAndPositionManager.getTotalSize return wrong value because get only topOffset from 93 row(this._lastMeasuredIndex = 93 - consequences of add new row) and estimate others rows size.
Also have the same problem, do you have any workaround?
+1 too..having same issue
It looks like the problem mostly resolved in version 9.21.1.
Now scroll jump only when I remove the last row and add new row instead.
