Detect if a view has been destroyed?

I’m having an issue with async uploading of images, mostly based on the ProseMirror upload example.

If for any reason the view is destroyed before the Promise is resolved, then I get an error:

index.js:4928 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'matchesNode')
    at EditorView.updateStateInner (index.js:4928)
    at EditorView.updateState (index.js:4899)
    at EditorView.dispatchTransaction (editor.cljs:286)
    at EditorView.dispatch (index.js:5176)
    at eval (placeholder.js:61)

I can’t find an official API to detect whether the view is destroyed so I can bail out of doing anything there. I could check for view.docView since it seems to be set to null when destroyed but would prefer an official API.

I’m also interested in this! At the moment I check for view.docView too.

That’s a reasonable thing to provide, I agree. prosemirror-view 1.23.0 adds an isDestroyed getter on EditorView.


Thanks! The changelog on the website seems to have stalled but I can see the release in npm. Much appreciated!

Oh, indeed, there was an invalid doc comment breaking the website build. Should be up to date again now.