In general, is there no problem if I return the node with the return value of the toDOM?

In general, is there no problem if I return the node with the return value of the toDOM?

toDOM(node) {
            const div = document.createElement('div');
            div.id = node.attrs.id;
            div.className = node.attrs.className;
            const iframe = document.createElement('iframe');
            iframe.src = node.attrs.src;
            div.appendChild(iframe);
            return div;
}

Is there a problem with the above code?

Is it a recommended specification? I wonder if it is not. If not recommended, I wonder what the main reasons are

It requires a special specification although I believe a more recent change may have supported DOM nodes as you are doing above.

https://prosemirror.net/docs/ref/#model.DOMOutputSpec

See Serialization and Parsing: ProseMirror Guide

As for reasons / performance, library author would know best. I dont think there should be a reason instantiating the DOM node there is less performant - the library just would check the dynamic type and do it later with the array syntax form. On second thought, there may be some performance layer that runs faster with the array syntax

1 Like

What kind of problem are you expecting? You seem to be conforming to the documented types, so I don’t see any issue.

1 Like

I was somewhat confused by the way it was phrased, but it seems like just a performance related question.

Why ever use the array syntax? Just convenience when it suffices? Is there any performance benefit to using it over instantiating a DOM node in application code - toDOM? Are all conformations going to operate predominately the same, performance wise?

Because it turns the ugly DOM manipulation code you’d usually have to write into a nice declarative one-liner, mostly.