question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

scrollToRow on List with dynamic heights and CellMeasurer doesn't always scroll to the proper location

See original GitHub issue

On a List with many items, all of dynamic height that are measured using a CellMeasurer, sometimes, jumping to a smaller row index n from larger row m index fails. This more frequently happens when m is much larger than n.

Here’s a plunkr to reproduce this behavior: https://plnkr.co/edit/B1463DyuByuIlmWTynRn

Steps:

  1. Enter a number between 600-800 in the box, and hit “Jump to row…”
  2. Enter a number between 200-400 in the box, and hit “Jump to row…”. Check whether the row is visible.
  3. Repeat steps 1 and 2, using a different number in the ranges each time, until you notice that the row in step 2 isn’t visible after the jump.

It usually takes anywhere from 1-5 repetitions for it to first occur. I’ve also noticed the error occurs with decreasing frequency the more jumps are done.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:22
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
yogurt1commented, Mar 27, 2018

I have solution

/**
 * Scroll to bottom of List/Grid
 */
const step = () => {
  const element = // .ReactVirtualized__Grid or List element
  const maxScrollTop = element.scrollHeight - element.clientHeight;

  if (maxScrollTop > element.scrollTop) {
     listRef.scrollToPosition(maxScrollTop); // Ref to <List /> component instance (or Grid)
     requestAnimationFrame(step);
  }
};

step();

You should do scroll until row index is >= startIndex and <= stopIndex scrollTop can be found by List#getOffsetForRow

3reactions
nullnoidcommented, May 3, 2018

I have the same issue, my workaround is to call scrollToRow again in the setState callback, like:

this.listNode.scrollToRow(idx);
this.setState({ scrollingToRow: idx }, () => {
    this.listNode.scrollToRow(idx);
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

scrollToRow result is off for dynamic height list - Stack Overflow
I think there's a misunderstanding or two above. Firstly, calling cache.clearAll() will erase all measurements- requiring CellMeasurer to ...
Read more >
A brand new website interface for an even better experience!
scrollToRow on List with dynamic heights and CellMeasurer doesn't always scroll to the proper location.
Read more >
List Virtualization - Patterns.dev
It's a windowing library by Brian Vaughn that renders only the items currently visible in a list (within a scrolling "viewport"). This means...
Read more >
types/react-virtualized@9.21.21 - jsDocs.io
This improves performance and makes scrolling smoother. ... scrollToRow: 0; ... list of elements with either fixed or dynamic heights.
Read more >
react-virtualized | Yarn - Package Manager
React components for efficiently rendering large, scrollable lists and tabular data. react, reactjs, react-component, virtual ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found