bvaughn/react-virtualized · critical · Error
Invalid size returned for cell ${i} of value ${size}
Error message
Invalid size returned for cell ${i} of value ${size} What it means
The cell size getter (`_cellSizeGetter`) returned undefined or NaN for a cell index, which the manager treats as a logic error and throws. null is allowed (it means CellMeasurer hasn't measured that index yet and yields a 0-size placeholder), but undefined/NaN indicate a broken size function. This is a hard error because layout math cannot proceed.
Source
Thrown at source/Grid/utils/CellSizeAndPositionManager.js:112
if (index < 0 || index >= this._cellCount) {
throw Error(
`Requested index ${index} is outside of range 0..${this._cellCount}`,
);
}
if (index > this._lastMeasuredIndex) {
let lastMeasuredCellSizeAndPosition = this.getSizeAndPositionOfLastMeasuredCell();
let offset =
lastMeasuredCellSizeAndPosition.offset +
lastMeasuredCellSizeAndPosition.size;
for (var i = this._lastMeasuredIndex + 1; i <= index; i++) {
let size = this._cellSizeGetter({index: i});
// undefined or NaN probably means a logic error in the size getter.
// null means we're using CellMeasurer and haven't yet measured a given index.
if (size === undefined || isNaN(size)) {
throw Error(`Invalid size returned for cell ${i} of value ${size}`);
} else if (size === null) {
this._cellSizeAndPositionData[i] = {
offset,
size: 0,
};
this._lastBatchedIndex = index;
} else {
this._cellSizeAndPositionData[i] = {
offset,
size,
};
offset += size;
this._lastMeasuredIndex = index;
}
}View on GitHub (pinned to c737715486)
Solutions
- Make the size getter return a number for every index < cellCount; add a fallback default.
- Coerce with Number() and validate with Number.isFinite before returning.
- Ensure any data the getter depends on is loaded before rendering, or use CellMeasurer (returning null) instead.
- Check for missing-return branches in the size function.
Example fix
// before
rowHeight={({index}) => heights[index]}
// after
rowHeight={({index}) => {
const h = heights[index];
return typeof h === 'number' && Number.isFinite(h) ? h : 32;
}} Defensive patterns
Strategy: validation
Validate before calling
const safeSize = (i) => {
const s = getSize(i);
if (s === null) return null; // CellMeasurer pending
const n = Number(s);
if (!Number.isFinite(n)) throw new Error(`size getter returned invalid value for cell ${i}: ${s}`);
return n;
}; Type guard
const isValidSize = (s) => s === null || (typeof s === 'number' && Number.isFinite(s));
Try / catch
try { grid.forceUpdate() } catch (e) { if (String(e.message).startsWith('Invalid size returned for cell')) { resetToDefaultSizes(); } else { throw e; } } Prevention
- Ensure size getters return a finite number for every index below cellCount
- Use CellMeasurer (null returns) instead of undefined for unmeasured cells
- Keep per-row size arrays in sync with row count
- Unit-test size getters against boundary indices
When it happens
Trigger: `rowHeight`/`columnHeight` (or cellSizeGetter) returning undefined for an index — e.g. a function that looks up a per-row height array that is shorter than rowCount; returning a non-numeric value; async size lookup without a fallback; size getter reading a record that doesn't exist yet.
Common situations: Passing `rowHeight={({index}) => heights[index]}` where heights isn't yet populated; returning a numeric string that fails after arithmetic; custom size functions with early-return paths that skip the return statement.
Related errors
- Rendered cell should include style property for positioning.
- Invalid metadata returned for cell ${index}: x:${cel
- Unexpected child type registered; only Grid/MultiGrid childr
- Requested index ${index} is outside of range 0..${this._cell
AI-assisted analysis of bvaughn/react-virtualized@c737715486 (2026-08-30).
Data as JSON: /api/errors/a029cad62f7594f2.
Report an issue: GitHub.