ianstormtaylor/slate · error · Error

Cannot apply a "split_node" operation at path [${path}] beca

Error message

Cannot apply a "split_node" operation at path [${path}] because the root node cannot be split.

What it means

A split_node operation was applied with an empty path [], which refers to the root editor node. The root node has no parent, so it cannot be split; split_node always targets a child within a parent.

Source

Thrown at packages/slate/src/interfaces/transforms/general.ts:354

            }

            delete selection[<keyof Range>key]
          } else {
            selection[<keyof Range>key] = value
          }
        }

        editor.selection = selection

        break
      }

      case 'split_node': {
        const { path, position, properties } = op
        const index = path[path.length - 1]

        if (path.length === 0) {
          throw new Error(
            `Cannot apply a "split_node" operation at path [${path}] because the root node cannot be split.`
          )
        }

        // Defend against malicious paths containing strings
        if (typeof index !== 'number') throw new Error('Index must be number')

        modifyChildren(editor, Path.parent(path), children => {
          const node = children[index]
          let newNode: Descendant
          let nextNode: Descendant

          if (Node.isText(node)) {
            const before = node.text.slice(0, position)
            const after = node.text.slice(position)
            newNode = {
              ...node,
              text: before,

View on GitHub (pinned to 72a37c701e)

Solutions

  1. Guard before splitting: ensure the target path is non-empty (path.length > 0)
  2. Fix the path computation that produced the root path; split a child node instead
  3. Validate/sanitize operations before applying them if they come from remote/serialized sources

Example fix

// before
Transforms.splitNodes(editor, { at: [] })

// after
if (at && at.length > 0) {
  Transforms.splitNodes(editor, { at })
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (!at || Path.isPath(at) === false || at.length === 0) {
  throw new Error('Cannot split the root node')
}
Transforms.splitNodes(editor, { at })

Type guard

const isChildPath = (p: Path): boolean => Array.isArray(p) && p.length > 0 && p.every(n => typeof n === 'number')

Prevention

When it happens

Trigger: Transforms.splitNodes(editor, { at: [] }); Editor.applyEditorOp/transform receiving split_node with path.length === 0; manual op construction with an empty path.

Common situations: Computing split paths with Path.parent/Path.next and accidentally producing []; replaying corrupted or hostile operation logs; off-by-one path math in custom transforms.

Related errors


AI-assisted analysis of ianstormtaylor/slate@72a37c701e (2026-08-27). Data as JSON: /api/errors/3981fbbb13f2ae42. Report an issue: GitHub.