Can I catch view destruction before the view is removed from the DOM?

I have a plugin that has the following code:

new Plugin({
  view(view) {
    return {
      destroy() {
        saveEditorState(props.textItem.id, view);
      }
    };
  }
})

This has worked for a long time, but I am upgrading webpack and something changed that no longer allows my saveEditorState function to complete execution before the node is removed from the DOM. Unfortunately, I need the node to be in the DOM while my function is running.

Is there something I can do to make sure my function is run while the node is still in the DOM?

Thanks!

No, that’s not something the library provides.

Thank you for your response, @marijn. I thought it was the destroy() method removing the node from the DOM, but it was actually React’s lifecycle that I was fighting. As soon as I thought of that as a possibility, I was able to fix my issue.