{"record":{"id":"3ee0d758e8823259","repo":"bvaughn/react-virtualized","slug":"invalid-metadata-returned-for-cell-index","errorCode":null,"errorMessage":"Invalid metadata returned for cell ${index}:\n        x:${cellMetadatum.x}, y:${cellMetadatum.y}, width:${cellMetadatum.width}, height:${cellMetadatum.height}","messagePattern":"Invalid metadata returned for cell (.+?):\n        x:(.+?), y:(.+?), width:(.+?), height:(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"source/Collection/utils/calculateSizeAndPositionData.js","lineNumber":26,"sourceCode":"  const cellMetadata = [];\n  const sectionManager = new SectionManager(sectionSize);\n  let height = 0;\n  let width = 0;\n\n  for (let index = 0; index < cellCount; index++) {\n    const cellMetadatum = cellSizeAndPositionGetter({index});\n\n    if (\n      cellMetadatum.height == null ||\n      isNaN(cellMetadatum.height) ||\n      cellMetadatum.width == null ||\n      isNaN(cellMetadatum.width) ||\n      cellMetadatum.x == null ||\n      isNaN(cellMetadatum.x) ||\n      cellMetadatum.y == null ||\n      isNaN(cellMetadatum.y)\n    ) {\n      throw Error(\n        `Invalid metadata returned for cell ${index}:\n        x:${cellMetadatum.x}, y:${cellMetadatum.y}, width:${cellMetadatum.width}, height:${cellMetadatum.height}`,\n      );\n    }\n\n    height = Math.max(height, cellMetadatum.y + cellMetadatum.height);\n    width = Math.max(width, cellMetadatum.x + cellMetadatum.width);\n\n    cellMetadata[index] = cellMetadatum;\n    sectionManager.registerCell({\n      cellMetadatum,\n      index,\n    });\n  }\n\n  return {\n    cellMetadata,\n    height,","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/bvaughn/react-virtualized/blob/c737715486f724586aee8870ebea1e9efb7b0bfe/source/Collection/utils/calculateSizeAndPositionData.js#L8-L44","documentation":"calculateSizeAndPositionData throws when a cell's metadata (from the Collection's `cellSizeAndPositionGetter`) contains null/NaN for x, y, width, or height. Collection requires numeric geometry for every cell to build its section index and total bounds. This is a hard error because invalid geometry corrupts layout and hit-testing.","triggerScenarios":"`cellSizeAndPositionGetter` returns an object with undefined/NaN/null fields, typically because the underlying data record is missing fields, the getter indexes into a sparse array, or it returns strings instead of numbers.","commonSituations":"Data loaded asynchronously so the getter runs before records are populated; typo in property names (e.g. `left` instead of `x`); JSON data with missing coordinates; index out of bounds returning undefined values.","solutions":["Fix `cellSizeAndPositionGetter` to always return numeric x, y, width, height for every index.","Coerce/validate values: Number(...) and defaults for missing fields.","Ensure the data array length matches `cellCount` and records are loaded before rendering.","Log the offending index/data inside the getter to find the bad record."],"exampleFix":"// before\ncellSizeAndPositionGetter={({index}) => data[index]}\n\n// after\ncellSizeAndPositionGetter={({index}) => {\n  const d = data[index];\n  return {\n    x: Number(d.x) || 0,\n    y: Number(d.y) || 0,\n    width: Number(d.width) || 0,\n    height: Number(d.height) || 0,\n  };\n}}","handlingStrategy":"validation","validationCode":"function validateCellMeta(m, i) {\n  const ok = [m.x, m.y, m.width, m.height].every(v => v != null && Number.isFinite(Number(v)));\n  if (!ok) throw new Error(`cellSizeAndPositionGetter returned invalid metadata at index ${i}: ${JSON.stringify(m)}`);\n  return m;\n}","typeGuard":"const isValidMeta = (m) => !!m && [m.x, m.y, m.width, m.height].every(v => v != null && Number.isFinite(Number(v)));","tryCatchPattern":"try { collection.render() } catch (e) { if (String(e.message).includes('Invalid metadata returned for cell')) { fixOrSkipBadRecord(e); } else { throw e; } }","preventionTips":["Validate data records before passing them to Collection","Coerce all coordinates with Number() in the getter","Sync cellCount with loaded data length","Log the offending index to locate bad records quickly"],"tags":["collection","layout","validation","geometry"],"backgroundTag":"invalid-cell-size-and-position","analyzedSha":"c737715486f724586aee8870ebea1e9efb7b0bfe","analyzedAt":"2026-08-30T00:33:38.249Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}