{"record":{"id":"a029cad62f7594f2","repo":"bvaughn/react-virtualized","slug":"invalid-size-returned-for-cell-i-of-value-siz","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":"critical","filePath":"source/Grid/utils/CellSizeAndPositionManager.js","lineNumber":112,"sourceCode":"    if (index < 0 || index >= this._cellCount) {\n      throw Error(\n        `Requested index ${index} is outside of range 0..${this._cellCount}`,\n      );\n    }\n\n    if (index > this._lastMeasuredIndex) {\n      let lastMeasuredCellSizeAndPosition = this.getSizeAndPositionOfLastMeasuredCell();\n      let offset =\n        lastMeasuredCellSizeAndPosition.offset +\n        lastMeasuredCellSizeAndPosition.size;\n\n      for (var i = this._lastMeasuredIndex + 1; i <= index; i++) {\n        let size = this._cellSizeGetter({index: i});\n\n        // undefined or NaN probably means a logic error in the size getter.\n        // null means we're using CellMeasurer and haven't yet measured a given index.\n        if (size === undefined || isNaN(size)) {\n          throw Error(`Invalid size returned for cell ${i} of value ${size}`);\n        } else if (size === null) {\n          this._cellSizeAndPositionData[i] = {\n            offset,\n            size: 0,\n          };\n\n          this._lastBatchedIndex = index;\n        } else {\n          this._cellSizeAndPositionData[i] = {\n            offset,\n            size,\n          };\n\n          offset += size;\n\n          this._lastMeasuredIndex = index;\n        }\n      }","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/bvaughn/react-virtualized/blob/c737715486f724586aee8870ebea1e9efb7b0bfe/source/Grid/utils/CellSizeAndPositionManager.js#L94-L130","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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."],"exampleFix":"// before\nrowHeight={({index}) => heights[index]}\n\n// after\nrowHeight={({index}) => {\n  const h = heights[index];\n  return typeof h === 'number' && Number.isFinite(h) ? h : 32;\n}}","handlingStrategy":"validation","validationCode":"const safeSize = (i) => {\n  const s = getSize(i);\n  if (s === null) return null; // CellMeasurer pending\n  const n = Number(s);\n  if (!Number.isFinite(n)) throw new Error(`size getter returned invalid value for cell ${i}: ${s}`);\n  return n;\n};","typeGuard":"const isValidSize = (s) => s === null || (typeof s === 'number' && Number.isFinite(s));","tryCatchPattern":"try { grid.forceUpdate() } catch (e) { if (String(e.message).startsWith('Invalid size returned for cell')) { resetToDefaultSizes(); } else { throw e; } }","preventionTips":["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"],"tags":["grid","cellsize","getter","validation"],"backgroundTag":"invalid-cell-size-returned","analyzedSha":"c737715486f724586aee8870ebea1e9efb7b0bfe","analyzedAt":"2026-08-30T00:33:38.249Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}