{"record":{"id":"000a6e29e8dc03a5","repo":"ianstormtaylor/slate","slug":"cannot-get-the-next-node-from-the-root-node","errorCode":null,"errorMessage":"Cannot get the next node from the root node!","messagePattern":"Cannot get the next node from the root node!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slate/src/editor/next.ts","lineNumber":21,"sourceCode":"\nexport const next: EditorInterface['next'] = (editor, options = {}) => {\n  const { mode = 'lowest', voids = false } = options\n  let { match, at = editor.selection } = options\n\n  if (!at) {\n    return\n  }\n\n  const pointAfterLocation = Editor.after(editor, at, { voids })\n\n  if (!pointAfterLocation) return\n\n  const [, to] = Editor.last(editor, [])\n\n  const span: Span = [pointAfterLocation.path, to]\n\n  if (Location.isPath(at) && at.length === 0) {\n    throw new Error(`Cannot get the next node from the root node!`)\n  }\n\n  if (match == null) {\n    if (Location.isPath(at)) {\n      const [parent] = Editor.parent(editor, at)\n      match = n => parent.children.includes(n)\n    } else {\n      match = () => true\n    }\n  }\n\n  const [next] = Editor.nodes(editor, { at: span, match, mode, voids })\n  return next\n}\n","sourceCodeStart":3,"sourceCodeEnd":36,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate/src/editor/next.ts#L3-L36","documentation":"Editor.next() returns the node after a given location; when 'at' is the root path itself (the empty path []), there is nothing after the root, so Slate throws. The check is explicit because the generic span-based search would otherwise produce nonsense.","triggerScenarios":"Calling Editor.next(editor, { at: [] }) or Editor.next(editor) when editor.selection or the default location resolves to the root path; passing a path variable that is an empty array (e.g. from Path.parent on a depth-1 path).","commonSituations":"Walking the tree in a loop and reaching the root; passing Node.path(editor, node) of the editor itself; default 'at' resolving to [] when selection is null and code assumes a deeper path.","solutions":["Guard before calling: skip when the path is empty (Path.isPath(at) && at.length === 0)","If iterating children of the root, use Editor.nodes with a mode/match, or iterate editor.children directly","Check the at value's derivation — it usually should be a child path like [0], not []"],"exampleFix":"// before\nconst next = Editor.next(editor, { at: path }) // path can be []\n\n// after\nconst next = path.length === 0 ? null : Editor.next(editor, { at: path })","handlingStrategy":"type-guard","validationCode":"const at = somePath\nif (!(Path.isPath(at) && at.length === 0)) {\n  const next = Editor.next(editor, { at })\n}","typeGuard":"const isNonRootPath = (p) => Array.isArray(p) && p.length > 0","tryCatchPattern":null,"preventionTips":["Check path.length > 0 before Editor.next/previous","Prefer Editor.nodes with mode/match for tree walking"],"tags":["slate","editor-api","traversal","root-node","path"],"backgroundTag":"invalid-editor-location","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}