title: How to troubleshoot row height adjustment with expandable rows with react virtualized list?
body: <p>I'm using expandable panels (Material-UI) in rows with a react virtualized list and have been having issues with the heights auto-adjusting. I've read several SO posts and some issues on dynamic row heights on the react-virtualized site, but I have a specific problem where it seems like there's an 'off by one' issue with when the row height is adjusted after panel is expanded/collapsed.</p>
  
  <p>Here's the expected behavior:</p>
  
  <ol>
  <li>Row panel expanded by default.</li>
  <li>User clicks expandable panel row.</li>
  <li>Row panel collapses.</li>
  <li>Row height adjusts to panel collapse.</li>
  </ol>
  
  <p>Here's the actual behavior <em>FOR THE FIRST CLICK</em>:</p>
  
  <ol>
  <li>Row panel expanded by default.</li>
  <li>User clicks expandable panel row.</li>
  <li>Row panel collapses.</li>
  <li>Row height does NOT adjust to panel collapse.</li>
  <li>HOWEVER, on subsequent clicks the row height DOES adjust, but to the 'opposite' state, which leads to an inconsistency - i.e when the the row panel is clicked to expand again, the row height is adjusted to the row height as if it were collapsed, and vice versa. So when the panel is collapsed there's a bunch of white space after it, and when it's technically expanded the row height is too small to see the content.</li>
  </ol>
  
  <p>I'm not sure what other info to include besides posting code and noting that the onRowClick() IS firing when the panels are collapsed/expanded.</p>
  
  <p>Here's the parent component:</p>
  
  <pre><code>import React, { Component } from 'react';
  import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer';
  import List from 'react-virtualized/dist/commonjs/List';
  import { CellMeasurer, CellMeasurerCache } from 'react-virtualized/dist/commonjs/CellMeasurer';
  import EquipSummaryRow from './EquipSummaryRow';
  import './EquipSummary.css';
  
  class EquipSummary extends Component {
    constructor(props) {
      super(props);
  
      this.cache = new CellMeasurerCache({
        fixedWidth: true,
      });
  
      this.rowRenderer = this.rowRenderer.bind(this);
      this.getDatum = this.getDatum.bind(this);
      this.onRowClick = this.onRowClick.bind(this);
    }
  
    getDatum(index) {
      const list = this.props.equipData;
  
      return list[index];
    }
  
    saveRef = (ref) =&gt; this.containerNode = ref;
  
    saveListRef = (ref) =&gt; {
      this.list = ref;
    }
  
    componentDidUpdate() {
      console.log('component updated');
      this.cache.clearAll();
      this.list.recomputeRowHeights();
    }
  
    onRowClick(e, index) {
      e.preventDefault();
      this.cache.clear(index);
      this.list.recomputeRowHeights();
      this.list.forceUpdateGrid();
    }
  
    rowRenderer({ index, key, parent, style }) {
      const datum = this.getDatum(index);
      return (
        &lt;div key={key} style={style}&gt;
          &lt;CellMeasurer
            cache={this.cache}
            columnIndex={0}
            key={key}
            rowIndex={index}
            parent={parent}
          &gt;
            {({ measure }) =&gt; (
              &lt;EquipSummaryRow
                onClick={(e, idx) =&gt; this.onRowClick(e, idx)}
                measure={measure}
                datum={datum}
                index={index}
              /&gt;
            )}
          &lt;/CellMeasurer&gt;
        &lt;/div&gt;
      );
    }
  
    render() {
      console.log('rendering..');
      return (
        &lt;div className="EquipSummary-AutoSizer" ref={this.saveRef}&gt;
          &lt;AutoSizer&gt;
            {({ width, height }) =&gt; (
              &lt;List
                ref={this.saveListRef}
                width={width}
                height={height}
                rowHeight={this.cache.rowHeight}
                rowCount={this.props.equipData.length}
                rowRenderer={this.rowRenderer}
                deferredMeasurementCache={this.cache}
                equipData={this.props.equipData}
              /&gt;
            )}
          &lt;/AutoSizer&gt;
        &lt;/div&gt;
      );
    }
  }
  
  export default EquipSummary;
  </code></pre>
  
  <p>And here's the component that represents a row:</p>
  
  <pre><code>import React, { Component } from 'react';
  import {
    Table,
    TableBody,
    TableHeader,
    TableHeaderColumn,
    TableRow,
    TableRowColumn,
  } from 'material-ui/Table';
  import { MuiThemeProvider } from 'material-ui/styles';
  import ExpansionPanel from '@material-ui/core/ExpansionPanel';
  import ExpansionPanelSummary from '@material-ui/core/ExpansionPanelSummary';
  import ExpansionPanelDetails from '@material-ui/core/ExpansionPanelDetails';
  import Typography from '@material-ui/core/Typography';
  
  
  class EquipSummaryRow extends Component {
    render() {
      const { datum } = this.props;
  
      return (
        &lt;div&gt;
          &lt;ExpansionPanel
            defaultExpanded
            onChange={e =&gt; this.props.onClick(e, this.props.index)}
          &gt;
            &lt;ExpansionPanelSummary expandIcon={&lt;div&gt;|&lt;/div&gt;}&gt;
              &lt;Typography&gt;{`${datum.type}      (id: ${datum.instance}, points: ${datum.points.length})`}&lt;/Typography&gt;
            &lt;/ExpansionPanelSummary&gt;
            &lt;ExpansionPanelDetails&gt;
              &lt;Table&gt;
                &lt;TableHeader
                  displaySelectAll={false}
                  adjustForCheckbox={false}
                &gt;
                  &lt;TableRow&gt;
                    &lt;TableHeaderColumn&gt;Device&lt;/TableHeaderColumn&gt;
                    &lt;TableHeaderColumn&gt;Object ID&lt;/TableHeaderColumn&gt;
                    &lt;TableHeaderColumn&gt;Type&lt;/TableHeaderColumn&gt;
                    &lt;TableHeaderColumn&gt;Name&lt;/TableHeaderColumn&gt;
                    &lt;TableHeaderColumn&gt;Description&lt;/TableHeaderColumn&gt;
                    &lt;TableHeaderColumn&gt;Units&lt;/TableHeaderColumn&gt;
                    &lt;TableHeaderColumn&gt;Value&lt;/TableHeaderColumn&gt;
                  &lt;/TableRow&gt;
                &lt;/TableHeader&gt;
                &lt;TableBody
                  displayRowCheckbox={false}
                &gt;
                  {datum.points.map((row, index) =&gt; (
                    &lt;TableRow key={row.id}&gt;
                      &lt;TableRowColumn&gt;{row.device}&lt;/TableRowColumn&gt;
                      &lt;TableRowColumn&gt;{row.objectID}&lt;/TableRowColumn&gt;
                      &lt;TableRowColumn&gt;{row.type}&lt;/TableRowColumn&gt;
                      &lt;TableRowColumn&gt;{row.name}&lt;/TableRowColumn&gt;
                      &lt;TableRowColumn&gt;{row.description}&lt;/TableRowColumn&gt;
                      &lt;TableRowColumn&gt;{row.units}&lt;/TableRowColumn&gt;
                      &lt;TableRowColumn&gt;{row.value}&lt;/TableRowColumn&gt;
                    &lt;/TableRow&gt;
                    ))}
                &lt;/TableBody&gt;
              &lt;/Table&gt;
            &lt;/ExpansionPanelDetails&gt;
          &lt;/ExpansionPanel&gt;
        &lt;/div&gt;
      );
    }
  }
  
  export default EquipSummaryRow;
  </code></pre>
  
  <p>Could this be an issue with how I'm using the cache? I've been beating my head with this so any suggestions appreciated!</p>