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

Scroll stutters/resets when using CellMeasurer with scrollToIndex on a List

Open athorwall opened this issue 9 years ago • 5 comments

When using CellMeasurer and scrollToIndex at the same time (on a List), scrolling upward seems to be broken. Explained in more detail here:

https://stackoverflow.com/questions/45993421/react-virtualized-scrolltoindex-not-working-with-cellmeasurer

Plunker:

https://plnkr.co/edit/XPF5D88WI9CErhkmrgAy?p=preview

athorwall avatar Sep 05 '17 16:09 athorwall

#610 should be the same problem

raffy2010 avatar Sep 06 '17 14:09 raffy2010

It actually seems that there are two distinct issues here:

  1. If you scroll upward toward unmeasured cells, then once the cells are measured the cells after them will jump down to accommodate the newly measured cells above them. The severity of the effect is related to the difference between a cell's default size and the actual size. This seems to be a very challenging issue to solve, and I think it's the focus of #610.

  2. Independent of that, when you use the scrollToIndex prop on a list that also uses CellMeasurer, the list seems to repeatedly jump back to the specified index (maybe whenever cells are measured?), as if the list seems to think that the scrollToIndex prop changed (and thus it must scroll to the new value) even though it has not. This issue is briefly mentioned in #610 but is mostly ignored--intuitively it seems like it's probably much easier to solve. At the very least, it seems like we can workaround this issue by calling List.scrollToRow() instead of setting the scrollToIndex prop. Example: https://plnkr.co/edit/8V4AtlqPtELrmDQMgBr7?p=preview (click "CLICK ME" and it will scroll to row 150; then attempt to scroll up and it should work fine).

athorwall avatar Sep 06 '17 20:09 athorwall

Using this for now. Thanks @athorwall

At the very least, it seems like we can workaround this issue by calling List.scrollToRow() instead of setting the scrollToIndex prop

SeanSassenrath avatar Sep 29 '17 21:09 SeanSassenrath

This seems to be another issue that was at least partially addressed in version 20.1. This plunker example:

https://plnkr.co/edit/UDbO2KKjQ3neDok0EOah?p=preview

is a fork of the example mentioned above, but with updated React and RV libraries. It seems to work unless the RV version is 20.0 or less.

Are there still cases that are not working with a current version of RV?

DavidCary avatar Sep 21 '19 03:09 DavidCary

This should be resolved in the upcoming 10.0 release. The scrollToIndex prop has been replaced by an imperative listRef.current.scrollToRow({ index, align }). This is a one-time scroll: the list doesn't keep re-applying it, so rows measured by CellMeasurer while you scroll up no longer pull the list back to that row.

bvaughn avatar Oct 18 '26 14:10 bvaughn