{"record":{"id":"4da965909c2825aa","repo":"ianstormtaylor/slate","slug":"cannot-move-a-path-path-to-new-path-newpat","errorCode":null,"errorMessage":"Cannot move a path [${path}] to new path [${newPath}] because the destination is inside itself.","messagePattern":"Cannot move a path \\[(.+?)\\] to new path \\[(.+?)\\] because the destination is inside itself\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slate/src/interfaces/transforms/general.ts","lineNumber":136,"sourceCode":"              `Cannot apply a \"merge_node\" operation at path [${path}] to nodes of different interfaces: ${Scrubber.stringify(\n                node\n              )} ${Scrubber.stringify(prev)}`\n            )\n          }\n\n          return replaceChildren(children, prevIndex, 2, newNode)\n        })\n\n        transformSelection = true\n        break\n      }\n\n      case 'move_node': {\n        const { path, newPath } = op\n        const index = path[path.length - 1]\n\n        if (Path.isAncestor(path, newPath)) {\n          throw new Error(\n            `Cannot move a path [${path}] to new path [${newPath}] because the destination is inside itself.`\n          )\n        }\n\n        const node = Node.get(editor, path)\n\n        modifyChildren(editor, Path.parent(path), children =>\n          removeChildren(children, index, 1)\n        )\n\n        // This is tricky, but since the `path` and `newPath` both refer to\n        // the same snapshot in time, there's a mismatch. After either\n        // removing the original position, the second step's path can be out\n        // of date. So instead of using the `op.newPath` directly, we\n        // transform `op.path` to ascertain what the `newPath` would be after\n        // the operation was applied.\n        const truePath = Path.transform(path, op)!\n        const newIndex = truePath[truePath.length - 1]","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate/src/interfaces/transforms/general.ts#L118-L154","documentation":"move_node relocates a node to newPath. It throws when the destination newPath is inside the subtree of the node being moved (i.e. path is an ancestor of newPath), since moving a node into itself is impossible and would corrupt the tree.","triggerScenarios":"Applying move_node with Path.isAncestor(path, newPath) true — e.g. moving [0] to [0,0] (into its own child). Typically from computed newPaths in drag-and-drop or nested-list reordering logic that doesn't exclude the dragged node's own subtree.","commonSituations":"Drag-and-drop implementations that allow dropping a container into its own descendants; nested list/block reordering where the new index is computed from the drop target without subtree checks; collaborative ops rebased incorrectly.","solutions":["Before moving, reject or adjust when Path.isAncestor(path, newPath) or Path.equals(path, newPath).","In drop handlers, filter out drop targets that are descendants of the dragged node (a common UX rule: can't drop into self).","If the move target was computed against a pre-move document, transform the newPath with the move_node operation first."],"exampleFix":"// before\nTransforms.moveNodes(editor, { at: path, to: newPath })\n\n// after\nif (!Path.isAncestor(path, newPath) && !Path.equals(path, newPath)) {\n  Transforms.moveNodes(editor, { at: path, to: newPath })\n}","handlingStrategy":"validation","validationCode":"if (!Path.isAncestor(path, newPath) && !Path.equals(path, newPath)) {\n  Transforms.moveNodes(editor, { at: path, to: newPath })\n}","typeGuard":"function isSafeMove(path: Path, newPath: Path): boolean {\n  return !Path.isAncestor(path, newPath) && !Path.equals(path, newPath)\n}","tryCatchPattern":null,"preventionTips":["In drag-and-drop, disallow drop targets inside the dragged node's subtree.","Exclude descendant paths when computing move destinations.","Transform newPath against prior operations when rebasing."],"tags":["slate","move-node","drag-and-drop","subtree"],"backgroundTag":"operation-apply-failed","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}