bvaughn/react-virtualized · warning

Fixed width CellMeasurerCache should specify a :defaultWidth

Error message

Fixed width CellMeasurerCache should specify a :defaultWidth greater than 0. Failing to do so will lead to unnecessary layout and poor performance.

What it means

Symmetric to error 2: when width is NOT fixed, `defaultWidth` (default 0) is used as the width estimate for unmeasured cells, causing unnecessary layout work and poor performance. Dev-mode console warning only.

Source

Thrown at source/CellMeasurer/CellMeasurerCache.js:91

    if (process.env.NODE_ENV !== 'production') {
      if (this._hasFixedHeight === false && this._hasFixedWidth === false) {
        console.warn(
          "CellMeasurerCache should only measure a cell's width or height. " +
            'You have configured CellMeasurerCache to measure both. ' +
            'This will result in poor performance.',
        );
      }

      if (this._hasFixedHeight === false && this._defaultHeight === 0) {
        console.warn(
          'Fixed height CellMeasurerCache should specify a :defaultHeight greater than 0. ' +
            'Failing to do so will lead to unnecessary layout and poor performance.',
        );
      }

      if (this._hasFixedWidth === false && this._defaultWidth === 0) {
        console.warn(
          'Fixed width CellMeasurerCache should specify a :defaultWidth greater than 0. ' +
            'Failing to do so will lead to unnecessary layout and poor performance.',
        );
      }
    }
  }

  clear(rowIndex: number, columnIndex: number = 0) {
    const key = this._keyMapper(rowIndex, columnIndex);

    delete this._cellHeightCache[key];
    delete this._cellWidthCache[key];

    this._updateCachedColumnAndRowSizes(rowIndex, columnIndex);
  }

  clearAll() {
    this._cellHeightCache = {};

View on GitHub (pinned to c737715486)

Solutions

  1. Pass an explicit `defaultWidth` greater than 0.
  2. Set `fixedWidth: true` if widths are constant, supplying that width.
  3. Match `defaultWidth` to the typical rendered width to reduce relayout.

Example fix

// before
const cache = new CellMeasurerCache({ fixedHeight: true });

// after
const cache = new CellMeasurerCache({ fixedHeight: true, defaultWidth: 200 });
Defensive patterns

Strategy: validation

Validate before calling

if (!opts.fixedWidth && !(opts.defaultWidth > 0)) throw new Error('Provide defaultWidth > 0 for CellMeasurerCache');

Prevention

When it happens

Trigger: `new CellMeasurerCache({fixedHeight: true})` (or neither fixed) without a `defaultWidth` greater than 0.

Common situations: Fixed-height rows with variable-width columns in Grid, but no `defaultWidth` supplied; assuming width is inferred from container.

Related errors


AI-assisted analysis of bvaughn/react-virtualized@c737715486 (2026-08-30). Data as JSON: /api/errors/9ca886461d9e361c. Report an issue: GitHub.