react-virtualized icon indicating copy to clipboard operation
react-virtualized copied to clipboard

[Bug] List with CellMeasurer not scrolling properly

Open javorka opened this issue 9 years ago • 7 comments

Description: When rendering a List with CellMeassure and scrollToIndex is set on the last index of the list. It gets "freezed" at that position, so it can't be scrolled up.

Reproducible here: Plunker

Affected version: v9.12.0

javorka avatar Nov 24 '17 11:11 javorka

Based on #871, I suspect CellMeasurer is not require in order to reproduce this bug.

bvaughn avatar Nov 25 '17 18:11 bvaughn

Some interesting info to add:

  • this happens no matter the index
  • this resets to the position only when scrolling up

In the Plunker, if you set the scrollToIndex={300} you can scroll down but not up:

rickhanlonii avatar Nov 27 '17 02:11 rickhanlonii

I got a little further on this and I think I understand the problem

What's happening is that the CellMeasurer is coming to new cells and calling Grid.invalidateCellSizeAfterRender. That's eventually getting to this line:

this._recomputeScrollTopFlag = scrollToRow >= 0 && rowIndex <= scrollToRow;

Which will reset the scrollTop on the next cDU only when scrolling up. If you reverse the <= to >= then the same problem happens when scrolling down

rickhanlonii avatar Nov 27 '17 23:11 rickhanlonii

Is there some viable solution available? I am using version 9.21.0 and this issue is still present :/ I am not even using CellMeasurer, so it's probably more related to #871.

danielkcz avatar Feb 01 '19 10:02 danielkcz

This appears to have been fixed as of version 9.20.1. At least the plunker example originally referenced seems to work with that version or newer.

DavidCary avatar Sep 18 '19 18:09 DavidCary

I should have written that this appears to have been partially fixed as of version 9.20.1. Can anyone share an example where the problem still exists in the current version?

DavidCary avatar Sep 19 '19 15:09 DavidCary

In version 10, scrollToIndex is no longer a controlled prop. Call scrollToRow({ index }) on the List's ref instead. It scrolls once and is never re-applied, so the list doesn't snap back to that row when CellMeasurer measures new rows, and scrolling up from the last row works.

bvaughn avatar Oct 18 '26 14:10 bvaughn