Skip to content

Commit 08a27f6

Browse files
committed
In the event that size or cell count decreases for a , remaining cells are no longer remeasured in order to verify the current scroll offset.
Instead the most recent measurements are used. This change should positively impact performance but should have no other affect.
1 parent 1ed936f commit 08a27f6

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
------------
33

4+
##### 7.22.2
5+
In the event that size or cell count decreases for a `Grid`, remaining cells are no longer remeasured in order to verify the current scroll offset.
6+
Instead the most recent measurements are used.
7+
This change should positively impact performance but should have no other affect.
8+
49
##### 7.22.1
510
`InfiniteLoader` now better handles `FlexTable` and `VirtualScroll` children by calling `forceUpdateGrid` when defined.
611
This prevents rows from being stuck in a visual "loading" state until a user scrolls.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "React components for efficiently rendering large, scrollable lists and tabular data",
44
"author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
55
"user": "bvaughn",
6-
"version": "7.22.1",
6+
"version": "7.22.2",
77
"homepage": "https://github.com/bvaughn/react-virtualized",
88
"main": "dist/commonjs/index.js",
99
"jsnext:main": "dist/es/index.js",

source/Grid/utils/updateScrollIndexHelper.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,11 @@ export default function updateScrollIndexHelper ({
6060
cellCount < previousCellsCount
6161
)
6262
) {
63-
scrollToIndex = cellCount - 1
64-
65-
const calculatedScrollOffset = cellSizeAndPositionManager.getUpdatedOffsetForIndex({
66-
containerSize: size,
67-
currentOffset: scrollOffset,
68-
targetIndex: scrollToIndex
69-
})
70-
63+
// We need to ensure that the current scroll offset is still within the collection's range.
64+
// To do this, we don't need to measure everything; CellMeasurer would perform poorly.
65+
// Just check to make sure we're still okay.
7166
// Only adjust the scroll position if we've scrolled below the last set of rows.
72-
if (calculatedScrollOffset < scrollOffset) {
67+
if (scrollOffset > cellSizeAndPositionManager.getTotalSize() - size) {
7368
updateScrollIndexCallback(cellCount - 1)
7469
}
7570
}

source/Grid/utils/updateScrollIndexHelper.test.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('updateScrollIndexHelper', () => {
3030
cellCount = undefined,
3131
cellSizeAndPositionManager,
3232
cellSize = 10,
33-
previousCellsCount = 100,
33+
previousCellsCount = undefined,
3434
previousCellSize = 10,
3535
previousScrollToAlignment = 'auto',
3636
previousScrollToIndex,
@@ -44,6 +44,9 @@ describe('updateScrollIndexHelper', () => {
4444
cellCount = cellCount === undefined
4545
? cellSizeAndPositionManager.getCellCount()
4646
: cellCount
47+
previousCellsCount = previousCellsCount === undefined
48+
? cellCount
49+
: previousCellsCount
4750

4851
let updateScrollIndexCallbackCalled = false
4952

@@ -123,6 +126,20 @@ describe('updateScrollIndexHelper', () => {
123126
})).toEqual(true)
124127
})
125128

129+
it('should not measure rows if :size or :cellCount have been reduced but only use already measured (or estimated) total size', () => {
130+
const cellSizeAndPositionManager = {
131+
getCellCount: () => CELL_SIZES.length,
132+
getTotalSize: () => 560
133+
}
134+
135+
expect(helper({
136+
cellSizeAndPositionManager,
137+
previousSize: 100,
138+
scrollOffset: 510,
139+
size: 50
140+
})).toEqual(false)
141+
})
142+
126143
it('should not call :updateScrollIndexCallback if there is no :scrollToIndex but :cellCount has been increased', () => {
127144
expect(helper({
128145
cellCount: 100,

0 commit comments

Comments
 (0)