Why NodeView is re-created?

Hi @marijn

I’m working on custom NodeView which display youtube embeddings in ProseMirror. Here is a sample code https://glitch.com/edit/#!/lapis-narwhal?path=index.js:1:0

I faced with the following issue: When user edit document above custom NodeView - sometimes (!) the NodeView is re-created under the hood. It is very annoying in case of youtube embedding since iframe is reloaded and widget blinks.

I’m able to reproduce the issue by typing 6 paragraphs above the NodeView and then select 6 to 1 paragraphs and remove a selection (see the video attached https://youtu.be/o-E-Hg61zNI)

There are a lot of cases when custom NodeView is a complex widget which takes noticeable time to reload. Do you think we can consider this as a bug? Can you please suggest a way to handle such cases if I did something wrong here?

Thank you in advance!

This is something that, in principle, you have to accept as the way the editor works—when reconciling the old and the new document, it sometimes won’t be able to figure out which DOM elements can be reused. It is good when we can avoid it, but a fully perfect solution would just be too slow.

In this case, though, it wasn’t too hard to avoid the redraw. This patch should help.

Thank you for full and detailed response @marijn.