{"record":{"id":"415c0de2cce30d3d","repo":"ianstormtaylor/slate","slug":"cannot-exit-root","errorCode":null,"errorMessage":"Cannot exit root","messagePattern":"Cannot exit root","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slate-react/src/chunking/chunk-tree-helper.ts","lineNumber":455,"sourceCode":"   * Assuming the current node is a chunk, move the pointer into that chunk\n   * repeatedly until the current node is a leaf\n   *\n   * @param end If true, place the pointer on the last node of the chunk.\n   * Otherwise, place the pointer on the first node.\n   */\n  private enterChunkUntilLeaf(end: boolean) {\n    while (this.pointerNode?.type === 'chunk') {\n      this.enterChunk(end)\n    }\n  }\n\n  /**\n   * Move the pointer to the parent chunk\n   */\n  private exitChunk() {\n    // istanbul ignore next\n    if (this.pointerChunk.type === 'root') {\n      throw new Error('Cannot exit root')\n    }\n\n    const previousPointerChunk = this.pointerChunk\n    this.pointerChunk = previousPointerChunk.parent\n    this.pointerIndex = this.pointerIndexStack.pop()!\n    this.cachedPointerNode = undefined\n    this.validateState()\n  }\n\n  /**\n   * Insert leaves immediately after the current node, leaving the pointer on\n   * the last inserted leaf\n   *\n   * Leaves are chunked according to the number of nodes already in the parent\n   * plus the number of nodes being inserted, or the minimum depth if larger\n   */\n  private rawInsertAfter(leaves: ChunkLeaf[], minDepth: number) {\n    if (leaves.length === 0) return","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate-react/src/chunking/chunk-tree-helper.ts#L437-L473","documentation":"Internal invariant of slate-react's chunk tree helper: exitChunk() moves the pointer to the parent chunk and refuses when the current chunk is the root, since the root has no parent. Called from readLeaf, returnToPreviousLeaf, insertAfter, and remove — all internal paths that should never exit from root given correct state. Marked 'istanbul ignore next'.","triggerScenarios":"Internal bug where the pointer index stack is unbalanced (more exitChunk calls than enterChunk calls); not producible through the public API.","commonSituations":"Slate-react chunking bugs; forks that call exitChunk/enterChunk out of order.","solutions":["Upgrade slate-react","Report the issue upstream with a minimal reproduction","In forks, verify enterChunk/exitChunk calls are balanced"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  edit()\n} catch (e) {\n  if (e.message === 'Cannot exit root') {\n    // internal bug: recover by remounting the editor\n  } else throw e\n}","preventionTips":["Maintain balanced enter/exit calls in any fork code touching chunk helpers","Report upstream with a reproduction"],"tags":["slate-react","chunking","internal-invariant","unreachable"],"backgroundTag":"library-internal-invariant","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}