{"record":{"id":"8a298a2927387aca","repo":"codex-team/editor.js","slug":"can-t-find-a-block-to-remove","errorCode":null,"errorMessage":"Can't find a Block to remove","messagePattern":"Can't find a Block to remove","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/components/modules/blockManager.ts","lineNumber":533,"sourceCode":"    this.removeBlock(blockToMerge);\n    this.currentBlockIndex = this._blocks.indexOf(targetBlock);\n  }\n\n  /**\n   * Remove passed Block\n   *\n   * @param block - Block to remove\n   * @param addLastBlock - if true, adds new default block at the end. @todo remove this logic and use event-bus instead\n   */\n  public removeBlock(block: Block, addLastBlock = true): Promise<void> {\n    return new Promise((resolve) => {\n      const index = this._blocks.indexOf(block);\n\n      /**\n       * If index is not passed and there is no block selected, show a warning\n       */\n      if (!this.validateIndex(index)) {\n        throw new Error('Can\\'t find a Block to remove');\n      }\n\n      this._blocks.remove(index);\n      block.destroy();\n\n      /**\n       * Force call of didMutated event on Block removal\n       */\n      this.blockDidMutated(BlockRemovedMutationType, block, {\n        index,\n      });\n\n      if (this.currentBlockIndex >= index) {\n        this.currentBlockIndex--;\n      }\n\n      /**\n       * If first Block was removed, insert new Initial Block and set focus on it`s first input","sourceCodeStart":515,"sourceCodeEnd":551,"githubUrl":"https://github.com/codex-team/editor.js/blob/5f45dabbe5690b7033b2f9047d3985add5045fdd/src/components/modules/blockManager.ts#L515-L551","documentation":"BlockManager.removeBlock looks up the block's index in its internal array; if the block is not present (already removed, or not managed by this editor) validateIndex fails and it throws. Callers include delete, backspace, mergeBlocks, removeSelectedBlocks, and clear.","triggerScenarios":"Removing a Block instance that was already destroyed (double-remove); removing a block belonging to another editor instance; removing during clear() when the list is already empty.","commonSituations":"Double-click handlers firing twice; undo/redo racing a delete; calling api.blocks.delete on stale BlockAPI references after re-render.","solutions":["Check the block still exists (getBlockById/getBlockByIndex) before removing","Debounce/flag click handlers so remove is attempted once","Re-acquire block references after render/clear operations"],"exampleFix":"// before\nblockManager.removeBlock(block);\n// after\nif (blockManager.blocks.indexOf(block) !== -1) {\n  blockManager.removeBlock(block);\n}","handlingStrategy":"try-catch","validationCode":"if (blockManager.getBlockById(block.id) !== undefined) { blockManager.removeBlock(block); }","typeGuard":"const isManagedBlock = (bm: BlockManager, block: Block): boolean => bm.blocks.indexOf(block) !== -1;","tryCatchPattern":"try { blockManager.removeBlock(block); } catch (e) { if (e instanceof Error && e.message.includes(\"Can't find a Block\")) return; /* already removed */ throw e; }","preventionTips":["Guard double-remove in click handlers","Re-acquire block references after structural changes"],"tags":["block-manager","remove","double-remove","editorjs"],"backgroundTag":"entity-not-found","analyzedSha":"5f45dabbe5690b7033b2f9047d3985add5045fdd","analyzedAt":"2026-08-27T22:50:23.124Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}