{"record":{"id":"1e863809621e5fb5","repo":"BookStackApp/BookStack","slug":"table-element-not-found","errorCode":null,"errorMessage":"Table Element Not Found","messagePattern":"Table Element Not Found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"resources/js/wysiwyg/lexical/table/LexicalTableNode.ts","lineNumber":315,"sourceCode":"  }\n\n  canSelectBefore(): true {\n    return true;\n  }\n\n  canIndent(): false {\n    return false;\n  }\n}\n\nexport function $getElementForTableNode(\n  editor: LexicalEditor,\n  tableNode: TableNode,\n): TableDOMTable {\n  const tableElement = editor.getElementByKey(tableNode.getKey());\n\n  if (tableElement == null) {\n    throw new Error('Table Element Not Found');\n  }\n\n  return getTable(tableElement);\n}\n\nexport function $convertTableElement(element: HTMLElement): DOMConversionOutput {\n  const node = $createTableNode();\n  setCommonBlockPropsFromElement(element, node);\n\n  const colWidths = getTableColumnWidths(element as HTMLTableElement);\n  node.setColWidths(colWidths);\n  node.setStyles(extractStyleMapFromElement(element));\n\n  return {node};\n}\n\nexport function $createTableNode(): TableNode {\n  return $applyNodeReplacement(new TableNode());","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/BookStackApp/BookStack/blob/18f8469a1c72f8cc8497e9372635e6dea5028071/resources/js/wysiwyg/lexical/table/LexicalTableNode.ts#L297-L333","documentation":"$getElementForTableNode fetches the table's DOM element via editor.getElementByKey(tableNode.getKey()). If the editor has no rendered element for that node key (headless editor, element removed from the DOM, or wrong editor instance), it returns null and this function throws 'Table Element Not Found'.","triggerScenarios":"Calling $getElementForTableNode with a headless editor or an editor whose table element is not mounted in the document; passing a TableNode from a different editor instance; calling outside an active reconciliation window after the node was removed.","commonSituations":"Programmatic table inspection in tests without rendering; accessing table DOM data after the table was deleted; using the wrong LexicalEditor's getElementByKey in multi-editor setups.","solutions":["Ensure the editor is attached to a real DOM (not createHeadlessEditor) and the table element is mounted before querying.","Confirm the TableNode belongs to the same editor you pass in (compare node's key existence via editor.getElementByKey first).","Call within an editor.update()/read() while the node is still attached; check $isTableNode(tableNode) and that it's part of the document root.","Wrap the call in try/catch and rebuild the DOM data lazily if the element may be transiently absent."],"exampleFix":"// before\nconst table = $getElementForTableNode(editor, tableNode); // throws if unmounted\n\n// after\nconst el = editor.getElementByKey(tableNode.getKey());\nif (!el) return null;\nconst table = getTable(el);","handlingStrategy":"validation","validationCode":"function $hasElementFor(editor: LexicalEditor, node: LexicalNode): boolean {\n  return editor.getElementByKey(node.getKey()) != null;\n}","typeGuard":"function $canGetTableDOM(editor: LexicalEditor, tableNode: TableNode): boolean {\n  return $isTableNode(tableNode) && editor.getElementByKey(tableNode.getKey()) !== null;\n}","tryCatchPattern":"try {\n  const table = $getElementForTableNode(editor, tableNode);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Table Element Not Found') return null;\n  throw e;\n}","preventionTips":["Only query table DOM data in DOM-backed editors inside update/read cycles","Confirm node and editor instance match in multi-editor setups","Check getElementByKey first when the node may be detached"],"tags":["lexical","table","dom","editor-key"],"backgroundTag":"table-element-not-found","analyzedSha":"18f8469a1c72f8cc8497e9372635e6dea5028071","analyzedAt":"2026-09-02T19:49:33.068Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}