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.

Bug with scrolling with WindowScroller -> AutoSizer -> Table and a big Header

See original GitHub issue

When Table component is used in conjunction with WindowScroller and AutoSizer, there is a bug with empty space on top of the table when the user is scrolling content down. But it works fine when content is being scrolled up.

Gif: http://www.giphy.com/gifs/l4FGCdxL20UsKANgs

Here is a Plunkr to reproduce: https://plnkr.co/edit/joaaAQPJLPy26Do4tA3k

Please try to scroll down and up and you will see the empty space on the top of the page.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:22 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
zefjcommented, Mar 21, 2018

@borNfreee sure, here’s a short write-up first:

The reason why the cells are disappearing is that the overscan is not applied to top-side rows when scrolling forwards. In line defaultOverscanIndicesGetter.js:25 you can see the overscan start index is set to 0 or startIndex (the first visible row determined by some other code), whichever is higher. The problem is the first visible row index value is incorrect if padding is added - some rows before that are still in view, so you need to take that into account and offset the overscanStartIndex by the value of however many rows your padding could fit, so Math.ceil(PADDING / ROW_HEIGHT) or something.

My padding is minuscule so I ended up just subtracting 1 from startIndex in the aforementioned line, but you can reuse the logic for backwards scrolling and subtract the overscanCellsCount argument as seen in line defaultOverscanIndicesGetter.js:33 instead, so that it uses the overscan values supplied via props.

export default function defaultOverscanIndicesGetter({
  cellCount,
  overscanCellsCount,
  scrollDirection,
  startIndex,
  stopIndex,
}: OverscanIndicesGetterParams): OverscanIndices {
  if (scrollDirection === SCROLL_DIRECTION_FORWARD) {
    return {
      // while scrolling forward, apply the overscan to top-side rows as well
      overscanStartIndex: Math.max(0, startIndex - overscanCellsCount), 
      overscanStopIndex: Math.min(
        cellCount - 1,
        stopIndex + overscanCellsCount,
      ),
    };
  } else {
    return {
      overscanStartIndex: Math.max(0, startIndex - overscanCellsCount),
      overscanStopIndex: Math.min(cellCount - 1, stopIndex),
    };
  }
}

This theoretically might need additional tweaking (or higher overscan values) for variable-height rows, but for fixed-height rows it works like a charm.

4reactions
maks-rafalkocommented, Jun 29, 2017

Guys, JFYI: I didn’t manage to fix this bug, but as a workaround - you can have two separate tables

  1. the first is for header
  2. the second is for data (with disableHeader=true)

It works and fixes this ugly bug, but as I said still a workaround. Please seee renderFakeTableAsAHeader and a complete example

private renderFakeTableAsAHeader(): JSX.Element {
    return (
        <AutoSizer disableHeight={true}>
            {({width, height}) => (
                <Table
                    autoHeight={true}
                    width={width}
                    height={height}
                    headerHeight={HEADER_HEIGHT}
                    rowHeight={this.props.cache.rowHeight}
                    rowCount={0}
                    rowGetter={() => {throw new Error('Logic Error'); }}
                >
                    {this.renderExtraColumns()}
                </Table>
            )}
        </AutoSizer>
    );
}

public render(): JSX.Element {
    return (
        <div>
            {this.renderFakeTableAsAHeader()}
            <WindowScroller scrollElement={scrollElement}>
                {({height, isScrolling, scrollTop}) => (
                    <AutoSizer disableHeight={true}>
                        {({width}) => (
                            <Table
                                autoHeight={true}
                                isScrolling={isScrolling}
                                scrollTop={scrollTop}
                                width={width}
                                height={height}
                                headerHeight={0}
                                disableHeader={true}
                                rowHeight={this.props.cache.rowHeight}
                                rowCount={vehicles.length}
                                rowGetter={({index}) => vehicles[index]}
                                noRowsRenderer={this.noRowsRenderer}
                                ref={(element) => {
                                    this.tableElement = element;
                                }}
                                deferredMeasurementCache={this.props.cache}
                            >
                        )}
                    </AutoSizer>
                )}
            </WindowScroller>
        </div>
    );
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug with scrolling with WindowScroller -> AutoSizer -> Table and a ...
When Table component is used in conjunction with WindowScroller and AutoSizer , there is a bug with empty space on top of the...
Read more >
React Virtualized: Table rows get cut off when autoHeight is on
I am using WindowScroller , AutoSizer , Table , and Column from React Virtualized,. In my 400 row table, about 30 rows appear...
Read more >
Using React-Virtualized InfiniteLoader, Autosizer, and Table ...
The infinite loader component relies on a few different functions and a property. loadMoreRows As you are scrolling through the table, this ...
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 >
Virtualize large lists with react-window - web.dev
Super large tables and lists can slow down your site's ... This improves both the rendering and scrolling performance of the list.
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