{"record":{"id":"96f0e1b42fe6daa8","repo":"bvaughn/react-virtualized","slug":"requested-index-index-is-outside-of-range-0","errorCode":null,"errorMessage":"Requested index ${index} is outside of range 0..${this._cellCount}","messagePattern":"Requested index (.+?) is outside of range 0\\.\\.(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"source/Grid/utils/CellSizeAndPositionManager.js","lineNumber":95,"sourceCode":"  getEstimatedCellSize(): number {\n    return this._estimatedCellSize;\n  }\n\n  getLastMeasuredIndex(): number {\n    return this._lastMeasuredIndex;\n  }\n\n  getOffsetAdjustment() {\n    return 0;\n  }\n\n  /**\n   * This method returns the size and position for the cell at the specified index.\n   * It just-in-time calculates (or used cached values) for cells leading up to the index.\n   */\n  getSizeAndPositionOfCell(index: number): SizeAndPositionData {\n    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) {","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/bvaughn/react-virtualized/blob/c737715486f724586aee8870ebea1e9efb7b0bfe/source/Grid/utils/CellSizeAndPositionManager.js#L77-L113","documentation":"CellSizeAndPositionManager.getSizeAndPositionOfCell throws when the requested cell index is negative or >= the cell count it knows about. The manager lazily computes cumulative offsets and cannot serve indices outside 0..cellCount. Usually indicates a stale or missing `cellCount` update relative to the indices being requested.","triggerScenarios":"Rendering with an old `rowCount`/`columnCount` while data shrinks; calling `scrollToRow`/`scrollToCell` with an index >= count; Grid internals requesting cells after data changed without `recomputeGridSize`; negative index from a size getter or overscan math on empty lists.","commonSituations":"Async data reload shrinking the dataset while scroll position references old indices; off-by-one in scrollToRow; rendering a Grid with rowCount 0 but a pending scroll offset; setState race during unmount.","solutions":["Always pass the current data length as rowCount/columnCount and update it with setState when data changes.","Clamp any scrollToRow/scrollToCell index to `Math.min(index, count - 1)` and `>= 0`.","Call `recomputeGridSize()` on the Grid after data changes.","Guard render logic to avoid rendering (or scrolling) while data is empty/loading."],"exampleFix":"// before\nlist.scrollToRow(selectedIndex);\n\n// after\nconst count = props.rowCount;\nif (count > 0) {\n  list.scrollToRow(Math.max(0, Math.min(selectedIndex, count - 1)));\n}","handlingStrategy":"validation","validationCode":"const safeIndex = (i, count) => (count > 0 ? Math.max(0, Math.min(i, count - 1)) : 0);\nif (index < 0 || index >= rowCount) return; // skip scroll/render call","typeGuard":"const inRange = (i, count) => Number.isInteger(i) && i >= 0 && i < count;","tryCatchPattern":"try { grid.scrollToCell({rowIndex, columnIndex}) } catch (e) { if (String(e.message).includes('outside of range')) { grid.recomputeGridSize(); } else { throw e; } }","preventionTips":["Always derive rowCount/columnCount from current data length via state","Clamp scrollToRow/scrollToCell arguments to valid range","Call recomputeGridSize after data mutations","Guard against rendering while data is empty/loading"],"tags":["grid","index-out-of-range","scroll","state"],"backgroundTag":"cell-index-out-of-range","analyzedSha":"c737715486f724586aee8870ebea1e9efb7b0bfe","analyzedAt":"2026-08-30T00:33:38.249Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}