{"record":{"id":"b864fb2a11487f60","repo":"ianstormtaylor/slate","slug":"cannot-get-the-element-at-path-path-because-i","errorCode":null,"errorMessage":"Cannot get the element at path [${path}] because it refers to a leaf node: ${Scrubber.stringify(\n            node\n          )}","messagePattern":"Cannot get the element at path \\[(.+?)\\] because it refers to a leaf node: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slate/src/utils/modify.ts","lineNumber":69,"sourceCode":"\n  const index = slicedPath.pop()!\n  root.children = replaceChildren(root.children, index, 1, modifiedNode)\n}\n\n/**\n * Replace the children of a node, replacing all ancestors\n */\nexport const modifyChildren = (\n  root: Ancestor,\n  path: Path,\n  f: (children: Descendant[]) => Descendant[]\n) => {\n  if (path.length === 0) {\n    root.children = f(root.children)\n  } else {\n    modifyDescendant<Element>(root, path, node => {\n      if (Node.isText(node)) {\n        throw new Error(\n          `Cannot get the element at path [${path}] because it refers to a leaf node: ${Scrubber.stringify(\n            node\n          )}`\n        )\n      }\n\n      return { ...node, children: f(node.children) }\n    })\n  }\n}\n\n/**\n * Replace a leaf, replacing all ancestors\n */\nexport const modifyLeaf = (\n  root: Ancestor,\n  path: Path,\n  f: (leaf: Text) => Text","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate/src/utils/modify.ts#L51-L87","documentation":"modifyChildren throws when the path refers to a Text (leaf) node but an element (container with children) is required. Transforms that operate on element children (e.g. splitting, merging, inserting nodes) need the target to be an Element; a leaf text node has no children to modify.","triggerScenarios":"A transform like splitNodes/mergeNodes/insertNodes given an at/element path resolving to a Text node; calling modifyChildren (directly or via ops) with a path ending at a text leaf, e.g. [0, 0] where node [0,0] is text.","commonSituations":"Path arithmetic that walks one level too deep (targeting text instead of its parent element); custom transforms assuming a node is an element without checking; mixed content where expected element position holds text.","solutions":["Check Node.isElement(Editor.node(editor, path)[0]) before calling element-level transforms","Use Path.parent(path) to operate on the containing element when you meant the element","Inspect the document (logger or React DevTools) at the failing path to correct path assumptions"],"exampleFix":"// before\nTransforms.splitNodes(editor, { at: textPath })\n\n// after\nconst [node] = Editor.node(editor, at)\nif (Element.isElement(node)) {\n  Transform.splitNodes(editor, { at })\n} else {\n  Transform.splitNodes(editor, { at: Path.parent(at) })\n}","handlingStrategy":"type-guard","validationCode":"const [node] = Editor.node(editor, path)\nif (!Element.isElement(node)) {\n  path = Path.parent(path)\n}\nTransforms.splitNodes(editor, { at: path })","typeGuard":"const isElementAt = (editor: Editor, p: Path): boolean =>\n  Element.isElement(Editor.node(editor, p)[0])","tryCatchPattern":null,"preventionTips":["Verify the node kind at a path before element-level transforms","Use Path.parent when you intend the containing element","Log document structure when path assumptions break"],"tags":["path","leaf-node","element","internal-utility","slate"],"backgroundTag":"wrong-node-type-at-path","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}