[Feature request] Destroy docView but keep the HTML nodes

Hello,

Would you be open to create a new method on EditorView so that we can ‘destroy’ the editor but keeping the HTML nodes. Something like that:

detach() {
    if (!this.docView) return
    destroyInput(this)
    this.destroyPluginViews({keep_nodes:true}) //optional
    this.docView.destroy()
    this.docView = null
  } 

(same as the destroy method without removing the nodeViews and this.dom)

The use case is for example.

I use prosemirror to render inline comments from a document, so there could be hundred of comments on a page. 99% of the comments are read only, so I could easily instanciate one EditoView, render the state of each comment, get this.dom.innerHTML and insert it on normal dom Nodes. But I have nodeViews which loads content async, and dynamic content inside the nodeViews (with dom listeners), so that would break it. The other option is to create one NodeView per comment, but the js stack size increase linearly in that case

I have for now forked prosemirror-view just to add that small function but was wondering if you were open to add that kind of things.

Thanks

That sounds too special-purpose and prone to creating all kinds of awkward edge cases (what about event handlers on the DOM elements that assume there’s a functioning view). Why not just clone the DOM or set the editor read-only?

That’s only a question of memory usage. If the editor is readonly the EditorViews still exist with all what it is linked to and consume memory (+ having the many eventListeners prosemirror subscribes to still active, even if I think their cost is cost is close to 0). Testing for 100 editors, shows 7Mo of js memory usage while only 2.2Mo when editors are destroyed and doms are copyed

As for cloning nodes, that could work but would make things more complex. (need to search nodes in the DOM instead of having their reference in the async code), keeping the nodes that prosemirror creates feels much more handy