How to dispatch a transaction from NodeView.destroy()?

I wish to communicate to my plugin that a node has been destroyed like so:

destroy() {
    const destroyTr = this.view.state.tr
     .setMeta('action', 'destroy')
     // @ts-ignore
     .setMeta('pos', this.getPos())

     this.view.dispatch(destroyTr);
}

This however gives me the following: RangeError: Applying a mismatched transaction.

Is this spposed to work? If yes can someone guide me on how to debug this kinda error or any alternate approach.

You shouldn’t dispatch transactions from destroy methods. Instead, update the state you want to update by looking at the changes in the transaction that caused the deletion, and seeing if they delete any relevant nodes.

1 Like