{"record":{"id":"98432fa37c793447","repo":"bvaughn/react-virtualized","slug":"invalid-size-returned-for-cell-i-of-value-siz-98432f","errorCode":null,"errorMessage":"Invalid size returned for cell ${i} of value ${size}","messagePattern":"Invalid size returned for cell (.+?) of value (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"source/utils/initCellMetadata.js","lineNumber":19,"sourceCode":"/**\n * Initializes metadata for an axis and its cells.\n * This data is used to determine which cells are visible given a container size and scroll position.\n *\n * @param cellCount Total number of cells.\n * @param size Either a fixed size or a function that returns the size for a given given an index.\n * @return Object mapping cell index to cell metadata (size, offset)\n */\nexport default function initCellMetadata({cellCount, size}) {\n  const sizeGetter = typeof size === 'function' ? size : () => size;\n\n  const cellMetadata = [];\n  let offset = 0;\n\n  for (var i = 0; i < cellCount; i++) {\n    let size = sizeGetter({index: i});\n\n    if (size == null || isNaN(size)) {\n      throw Error(`Invalid size returned for cell ${i} of value ${size}`);\n    }\n\n    cellMetadata[i] = {\n      size,\n      offset,\n    };\n\n    offset += size;\n  }\n\n  return cellMetadata;\n}\n","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/bvaughn/react-virtualized/blob/c737715486f724586aee8870ebea1e9efb7b0bfe/source/utils/initCellMetadata.js#L1-L32","documentation":"initCellMetadata() precomputes the size and cumulative offset of every cell (rows/columns) for react-virtualized's CellSizeAndPositionManager. Each size comes from your sizeGetter (e.g. cellSizeGetter / rowHeight / columnWidth). If the getter returns null, undefined, or NaN, no valid layout can be built, so the function throws while iterating cell index i.","triggerScenarios":"Passing a rowHeight/columnWidth (or custom sizeGetter) that returns NaN or null for some index — e.g. a function form like rowHeight={({index}) => heights[index]} where the data array is empty or the index is missing, or returning a non-numeric string via arithmetic that yields NaN.","commonSituations":"Dynamic row height computed from unloaded/async data (returns undefined before data loads), height function dividing by zero or by a missing measurement, passing a string height like 'auto' into arithmetic, or a getter written against the wrong react-virtualized API version (different callback signature).","solutions":["Fix the sizeGetter/rowHeight/columnWidth so it always returns a finite number for every index 0..cellCount-1, using a fallback: heights[index] || DEFAULT_HEIGHT.","If sizes depend on async data, don't render the grid (or set rowCount to 0) until the data is available, then recompute.","For variable heights computed in render, use the measured results with a default and memoize so the getter never returns undefined.","Log sizeGetter({index: i}) output for the failing index i (given in the message) to find which data entry is bad."],"exampleFix":"// before\nconst rowHeight = ({index}) => rowHeights[index]; // undefined when data incomplete\n\n// after\nconst DEFAULT_ROW_HEIGHT = 40;\nconst rowHeight = ({index}) => {\n  const h = rowHeights[index];\n  return Number.isFinite(h) ? h : DEFAULT_ROW_HEIGHT;\n};","handlingStrategy":"validation","validationCode":"function validateSizeGetter(sizeGetter, cellCount) {\n  for (let i = 0; i < cellCount; i++) {\n    const size = sizeGetter({index: i});\n    if (size == null || !Number.isFinite(Number(size))) {\n      throw new Error(`sizeGetter returned invalid size ${size} at index ${i}`);\n    }\n  }\n}\n// call before rendering the Grid/List/Table","typeGuard":"function isValidCellSize(size) {\n  return size != null && Number.isFinite(Number(size));\n}","tryCatchPattern":"try {\n  const metadata = initCellMetadata({cellCount, sizeGetter});\n} catch (e) {\n  if (String(e.message).startsWith('Invalid size returned for cell')) {\n    console.error('Fix sizeGetter: it returned a non-numeric value', e.message);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always return a finite number from rowHeight/columnWidth/sizeGetter; apply a DEFAULT_HEIGHT fallback with Number.isFinite","Do not render virtualized components until their backing data is fully loaded (or set rowCount/cellCount to 0 meanwhile)","Beware string values ('auto', '100%') in size functions — resolve them to pixels before returning","When upgrading react-virtualized, confirm your size function still matches the expected ({index, cache}) callback signature"],"tags":["invalid-size","nan","virtualization","cell-metadata"],"backgroundTag":"invalid-size-getter-return","analyzedSha":"c737715486f724586aee8870ebea1e9efb7b0bfe","analyzedAt":"2026-08-30T00:33:38.249Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}