We are replacing some top-level nodes (images, iframes etc) with a node view, in order to be able to show some UI (e.g. a close button).
However it seems like there’s an issue with the drop cursor plugin that calls .nodeDOM on the node which just returns null for node views, which then promptly crashes.
Is that a known issue? Should we work around that?
The way we reproduce is a bit more complicated since it might be some peculiarity of our schema, but it ends up like this:
Have two editor instances side-by-side.
One editor has an image in the content
Drag the image from editor A to editor B
Hover over editor B and see the dropcursor being rendered.
If you hover over a paragraph, then you have 3 options: above/below/inside - inside as in, between characters, getting a vertical cursor.
Make sure the drop cursor is in between characters, and release
crash
There’s a few more complications:
Our images can only appear within a figure, and neither figures nor images are inline content. We expected that the drop cursor shouldn’t even render in between characters but looking at the code, it doesn’t seem to know what actually is being hovered over the editor.
The figure is the NodeView
We have set both images and figures to be draggable, since if we made only the figure being draggable then the UX is sub-optimal (you have to first select the figure somehow to drag it). There are subtle differences.
When dragging an external file, then the crash doesn’t happen. Not sure what the difference in the codepath is - but it seems like everything works as expected - if you drop in between characters, then the paragraph is split and the image ends up in the middle - I guess this is because we handle the drop event manually?
That is, the updateOverlay method as called by the update method after a transaction is dispatched and the updated state is set to the view (via .updateState)
And it gets even more weird in the debugger. At this point, the cursor should (in my head) be removed - the drop is over. before and after are both falsey (well, before is null and after seems to be not available, whatever that means. I’m not sure I’m using the watch expressions correctly.
But indeed, if I understand correctly - the cursorPos is pointing to the image Node, which is indeed not rendered in the editor since it’s rendered by the NodeView (the figure), which is why nodeDOM returns null.
@marijn Getting a minimal repro is a bit tough, I hope the info I provided helps - if not, please let me know and I’ll dedicate some more time to it. Thanks for your attention!
I also ran into this issue with the dropcursor + dragging an image that is rendered with a nodeview, but for me the issue is the subsequent getBoundingClientRect call below the one that was patched. I can try put some more effort into creating a minimal reproduction if wanted.