Detect if a block has been deleted

Maybe you will find this snippet helpful. I’m still searching for a better way to do this but as far as I can tell blocks are not aware of their own deletion. Instead we have to monitor the blocks from above. If you have a parent block type that has children, you can subscribe to core/block-editor and use getBlocks() to check the length of children and if the new length is lower than the old length then you have caught a deletion.

const getBlockList = () => wp.data.select( 'core/block-editor' ).getBlocks();
  
let blockList = getBlockList();

wp.data.subscribe( () => {

  const newBlockList = getBlockList();

  if ( newBlockList.length < blockList.length ) {
    console.log( 'A block was removed!!' );
  }

  blockList = newBlockList;

} );