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 notes: causes of height measurement errors, and how to fix them.

See original GitHub issue

CellMeasurer renders each cell outside of the table context, and hence does not apply any inherited styling from outer elements. This kind of issue can sometimes be hard to debug. An approach I’ve used is to dump Window.getComputedStyle() on both the CellMeasurer and the visible version of cells at issue, and diff them. This requires using a breakpoint in CellMeasurer’s “measureCell”, since the hidden renderings are transient. [If other users need to do this also, an enhancement that makes the hidden renderings accessible to a handler might be useful.]

Another source of errors is vertical alignment. This may only occur with table layout. If different cells have different alignment, the vertical space required for a row can be larger than that measured for any single cell. Similarly, a baseline-aligned large image in one cell can require space above the first row of text in other cells, and thus forces padding that is not counted other cells’ sizes. If one of these other cells is the tallest cell in the row (e.g. multiple lines), it will not count the image size above the top line’s lineHeight. I’ve been able to work around this by using consistent top alignment. There might be a way for CellMeasurer to measure this vertical-alignment-forced padding and correct for it, but I haven’t dug into it.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
misha-panyushkincommented, Jan 21, 2017

@estaub, @nsuthar0914 you should better use container option and pass it into cell-measurer. I run into a problem of this kind and found easy to pass appropriate container node to handle css styles inheritance for correct height calculations. In my case it was List element itself:

<CellMeasurer
    {...cellMeasurerProps}
    container={() => this.listInstanceRef}
>
    {({ getRowHeight }) => {
        return (
            <List
                ref={ref => this.listInstanceRef = ref}
                rowHeight={getRowHeight}
                {...listProps}
            />
        )
    }}
</CellMeasurer>
0reactions
nsuthar0914commented, Jan 23, 2017

@estaub @bvaughn @misha-panyushkin i couldn’t get cellmeasurer to give the heights that i wanted the first time, so i simply added another list to get and set heights on componentdidmount and onScroll –

  componentDidMount() {
    this.handleResizeWidth();
  }

  handleResizeWidth() {
    let that = this;
    setTimeout(function() {
      that.itemHeights = that.list.map((listItem, index) => {
        let item = document.getElementById(`item-${index}`);
        if (item) {
          return item.clientHeight;
        } else {
          return null;
        }
      });
      that.cellmeasurer && that.cellmeasurer.resetMeasurements();
      that.grid && that.grid.recomputeGridSize();
    }, 10);
  }

  handleScroll() {
    let heightsToBeUpdated = false;
    this.itemHeights && this.itemHeights.forEach((listItem, index) => {
      let item = document.getElementById(`item-${index}`);
      if (!listItem && !!item) {
        this.itemHeights[index] = item.clientHeight;
        heightsToBeUpdated = true;
      }
    });
    if (heightsToBeUpdated) {
      this.cellmeasurer && this.cellmeasurer.resetMeasurements();
      this.grid && this.grid.recomputeGridSize();
    }
  }

It isn’t elegant at all and if i have like 100 of my heavy list item components in the list and scroll too fast, there is flickering. But this will have to do for now, i guess.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Virtualized table with CellMeasurer is not calculating ...
I think that the problem is because each cell's height is calculated before it's content is loaded. I used the parameter measure of...
Read more >
Lecture note #2, Physical Measurements, PHYS 201L
It doesn't mean to make a mistake. Mistakes, such as measuring a 45.0 cm long table to be 35.0 cm, can be avoided...
Read more >
Measurements and Error Analysis - WebAssign
Measurement errors may be classified as either random or systematic, depending on how the measurement was obtained (an instrument could cause a random...
Read more >
Rendering large lists with React Virtualized - LogRocket Blog
In this article, I'll show you how to use react-virtualized to display ... CellMeasurer, to dynamically measure the width and height of the ......
Read more >
ANTHROPOMETRY PROCEDURES MANUAL - CDC
Actual stature, weight, and body measurements (including skinfolds and ... It is the recorder's role to "assist" the examiner in obtaining correct ......
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