BookStackApp/BookStack · error · Error

Table row target index out of range

Error message

Table row target index out of range

What it means

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.

Source

Thrown at resources/js/wysiwyg/lexical/table/LexicalTableUtils.ts:179

    throw new Error('Expected table cell to be inside of table row.');
  }

  const targetRowNode = tableRows[indexToDelete];
  targetRowNode.remove();
  return tableNode;
}

export function $insertTableRow(
  tableNode: TableNode,
  targetIndex: number,
  shouldInsertAfter = true,
  rowCount: number,
  table: TableDOMTable,
): TableNode {
  const tableRows = tableNode.getChildren();

  if (targetIndex >= tableRows.length || targetIndex < 0) {
    throw new Error('Table row target index out of range');
  }

  const targetRowNode = tableRows[targetIndex];

  if ($isTableRowNode(targetRowNode)) {
    for (let r = 0; r < rowCount; r++) {
      const tableRowCells = targetRowNode.getChildren<TableCellNode>();
      const tableColumnCount = tableRowCells.length;
      const newTableRowNode = $createTableRowNode();

      for (let c = 0; c < tableColumnCount; c++) {
        const tableCellFromTargetRow = tableRowCells[c];

        invariant(
          $isTableCellNode(tableCellFromTargetRow),
          'Expected table cell',
        );

View on GitHub (pinned to 18f8469a1c)

Solutions

  1. Clamp targetIndex to 0..tableRows.length-1 before inserting
  2. Recompute the row index from the current selection after any table mutations
  3. Refresh the DOM table map (TableDOMTable) so counts match the node tree
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at resources/js/wysiwyg/lexical/table/LexicalTableUtils.ts:179 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BookStackApp/BookStack@18f8469a1c (2026-09-02). Data as JSON: /api/errors/5bcd4a8bf99b2208. Report an issue: GitHub.