nodeView dragging results in duplicates bug

Hi Marijn,

I’m working on prosemirror-image-plugin and as Roman in another thread mentioned there are issues with dragging image nodes if they have a nodeview. He says that the following commit in prosemirror-view broke the beaviour.

I couldn’t make it right. If I return false from the nodeView’s update method then the dragging is fine, but then I have issues with an infinite loop if I set the image node’s src a bit later ( I want to do that because the plugin has a feature that enables getting the image data from an authenticated endpoint ).

I’d have one additional question: does the nodeView’s dom have to reflect parseDOM & toDOM in the schema? AFAIK they’re important even if one has a nodeView since they are necessary for correct copy & pasting etc, but copying from the editor serializes with toDOM from the ProseMirror state. I’m asking because the plugin has an option for a contentDOM title, I’m working on resize arrows, it already has an on-hover layout selector etc, and I don’t want to dig into this if not necessary.

I’ve made a minimal example ( not with the plugin, just a nodeview ) which shows the issue. Thanks & let me know if there’s something I could help with. V

On the minimal example you have to drag the node up & down a few times for it to happen ( it usually happens to me the first time ). If the image is block then it happens on the downward direction, with inline it happens upward.

I couldn’t reproduce this, but I can kind of see how it might happen if you blindly return true from update without checking whether the given node is actually a node you can display, or updating any DOM. Just returning false will indeed just cause the node to be recreated. So actually implement a proper update method that checks if the node given is an image, and updates the DOM and returns true only when it is.

Also, if you’re messing with the DOM after initialization (as in the setTimeout), wouldn’t it make sense to make ignoreMutation return true, so that the editor doesn’t re-parse the entire node when you do that?

Thanks Marijn, your tips were useful.