{"record":{"id":"8029d7ab6967f0b2","repo":"ianstormtaylor/slate","slug":"cannot-get-the-descendant-node-at-path-path-b","errorCode":null,"errorMessage":"Cannot get the descendant node at path [${path}] because it refers to the root editor node instead: ${Scrubber.stringify(\n          node\n        )}","messagePattern":"Cannot get the descendant node at path \\[(.+?)\\] because it refers to the root editor node instead: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slate/src/interfaces/node.ts","lineNumber":321,"sourceCode":"    while (reverse ? index >= 0 : index < children.length) {\n      const child = Node.child(ancestor, index)\n      const childPath = path.concat(index)\n      yield [child, childPath]\n      index = reverse ? index - 1 : index + 1\n    }\n  },\n\n  common(root: Node, path: Path, another: Path): NodeEntry {\n    const p = Path.common(path, another)\n    const n = Node.get(root, p)\n    return [n, p]\n  },\n\n  descendant(root: Node, path: Path): Descendant {\n    const node = Node.get(root, path)\n\n    if (Node.isEditor(node)) {\n      throw new Error(\n        `Cannot get the descendant node at path [${path}] because it refers to the root editor node instead: ${Scrubber.stringify(\n          node\n        )}`\n      )\n    }\n\n    return node\n  },\n\n  *descendants(\n    root: Node,\n    options: NodeDescendantsOptions = {}\n  ): Generator<NodeEntry<Descendant>, void, undefined> {\n    for (const [node, path] of Node.nodes(root, options)) {\n      if (path.length !== 0) {\n        // NOTE: we have to coerce here because checking the path's length does\n        // guarantee that `node` is not a `Editor`, but TypeScript doesn't know.\n        yield [node, path] as NodeEntry<Descendant>","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate/src/interfaces/node.ts#L303-L339","documentation":"Node.descendant() attempts to resolve a path inside a node tree, but the resolved node is the editor itself. In Slate, the editor is the root container and not a 'descendant', so the API refuses to return it. This almost always means the path was empty ([]) or pointed back to the root.","triggerScenarios":"Calling Node.descendant(editor, []) or Editor.node() with a path of length 0; passing a path computed from Path.parent on a top-level path ([0] -> []); passing an editor where a descendant node was expected.","commonSituations":"Walking up with Path.parent until the root and then calling descendant on the result; off-by-one in path math that produces an empty path; calling Editor.node(editor, path) where path was normalized to the root.","solutions":["Check that the path is non-empty and does not resolve to the root before calling descendant: if (path.length === 0) handle root explicitly.","If you actually want the root, use the editor object directly instead of Node.descendant.","Use Node.get with your own Editor.isEditor check if you need the root case to be handled generically.","Verify Path.parent() results: it throws only on [], so guard paths of length 1 before descending further."],"exampleFix":"// before\nconst node = Node.descendant(editor, Path.parent(somePath))\n\n// after\nconst p = Path.parent(somePath)\nconst node = p.length === 0 ? editor : Node.descendant(editor, p)","handlingStrategy":"type-guard","validationCode":"if (path.length === 0) { /* root: use editor directly */ }","typeGuard":"const isNonRootPath = (p: Path): boolean => p.length > 0 && !Editor.isEditor(Node.getIf(editor, p))","tryCatchPattern":null,"preventionTips":["Never feed Path.parent results into descendant without checking for the empty path.","Treat [] as the editor and branch explicitly before descendant lookups."],"tags":["slate","path","editor","descendant","root-node"],"backgroundTag":"slate-invalid-path","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}