{"record":{"id":"5bcd4a8bf99b2208","repo":"BookStackApp/BookStack","slug":"table-row-target-index-out-of-range","errorCode":null,"errorMessage":"Table row target index out of range","messagePattern":"Table row target index out of range","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"resources/js/wysiwyg/lexical/table/LexicalTableUtils.ts","lineNumber":179,"sourceCode":"    throw new Error('Expected table cell to be inside of table row.');\n  }\n\n  const targetRowNode = tableRows[indexToDelete];\n  targetRowNode.remove();\n  return tableNode;\n}\n\nexport function $insertTableRow(\n  tableNode: TableNode,\n  targetIndex: number,\n  shouldInsertAfter = true,\n  rowCount: number,\n  table: TableDOMTable,\n): TableNode {\n  const tableRows = tableNode.getChildren();\n\n  if (targetIndex >= tableRows.length || targetIndex < 0) {\n    throw new Error('Table row target index out of range');\n  }\n\n  const targetRowNode = tableRows[targetIndex];\n\n  if ($isTableRowNode(targetRowNode)) {\n    for (let r = 0; r < rowCount; r++) {\n      const tableRowCells = targetRowNode.getChildren<TableCellNode>();\n      const tableColumnCount = tableRowCells.length;\n      const newTableRowNode = $createTableRowNode();\n\n      for (let c = 0; c < tableColumnCount; c++) {\n        const tableCellFromTargetRow = tableRowCells[c];\n\n        invariant(\n          $isTableCellNode(tableCellFromTargetRow),\n          'Expected table cell',\n        );\n","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/BookStackApp/BookStack/blob/18f8469a1c72f8cc8497e9372635e6dea5028071/resources/js/wysiwyg/lexical/table/LexicalTableUtils.ts#L161-L197","documentation":"Range guard in $insertTableRow: targetIndex is negative or >= the number of child rows of the TableNode, so the requested insert position does not exist. Input at fault: an out-of-bounds row index computed from selection or UI state.","triggerScenarios":"Thrown at resources/js/wysiwyg/lexical/table/LexicalTableUtils.ts:179 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Clamp targetIndex to 0..tableRows.length-1 before inserting","Recompute the row index from the current selection after any table mutations","Refresh the DOM table map (TableDOMTable) so counts match the node tree"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"18f8469a1c72f8cc8497e9372635e6dea5028071","analyzedAt":"2026-09-02T19:49:33.068Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}