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.

CellMeasurer has wrong measurements for FIRST batch only

See original GitHub issue

I’m using the CellMeasurer in order to calculate a VirtualScroll’ row’s height, and it’s using a completely wrong measurement for the initial batch of visible rows.

This ends up something like the following (the top 4 rows were a part of the initial batch, and have a very tall height):

The virtualized components that I’m using are as follows:

<WindowScroller>
    { ({ height, scrollTop }) =>

        <AutoSizer disableHeight>
            { ({ width }) =>

                <CellMeasurer
                    cellRenderer={ cell => this.renderVirtualRow(cell.rowIndex) }
                    columnCount={ 1 }
                    rowCount={ items.length }
                    width={ width } >
                    { ({ getRowHeight }) =>

                        <VirtualScroll
                            autoHeight
                            style={ { background: '#EEE' } }
                            width={ width }
                            height={ height }
                            scrollTop={ scrollTop }
                            rowCount={ items.length }
                            rowHeight={ getRowHeight }
                            rowRenderer={ row => this.renderVirtualRow(row.index) } />

                    }
                </CellMeasurer>

            }
        </AutoSizer>

    }
</WindowScroller>

If I scroll, the rows that get rendered all have the correct heights, but the initial batched rows are still all wrong.

It’s happening on both Chrome and FireFox.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
damusnetcommented, May 25, 2017

Hi @bvaughn

FWIW I encountered the same issue, in a Next.js SSR app. I think your diagnostic is correct, but I couldn’t figure out how to improve the measurement as everything in my design is fluid, and inside a swipe-view to make it even more complicated.

My solution was as follows:

  componentDidMount() {
    if (this.list) {
      setTimeout(() => {
        cache.clearAll();
        this.list.recomputeRowHeights();
      }, 0);
    }
  }
0reactions
bvaughncommented, Aug 23, 2016

Closing for now. Don’t have enough info to help diagnose this further.

Comments will still notify me via email- so if you get a chance to provide a Plunker or some way to reproduce, let me know and I’ll be happy to take another look. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Row heights are wrong with react-virtualized List and ...
I am brand new to React.js (this is my first project in React, so some of the bad design is probably attributable to...
Read more >
types/react-virtualized@9.21.21 - jsDocs.io
Typically cells are only measured as needed and estimated sizes are used for cells that have not yet been measured. This method ensures...
Read more >
masonic - npm
An autosizing masonry grid component that only renders items currently viewable in the window. This component will change its column count to ...
Read more >
react-virtualized List TypeScript Examples - ProgramCreek.com
This page shows TypeScript code examples of react-virtualized List. ... FC<ListProps> = ({ width, height, rowCount, rowHeight, rowRenderer, ...
Read more >
Create a Virtualized List with Auto Sizing Cells using react ...
These allow for dynamic just-in-time measurements of your rows. [00:19] The first thing we need to do is set up a cache. Say...
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