DOMSerializer ignores nodes views related to nodes

In order to customise the built-in prosemirror-tables’s table_cell, i had to add a custom node view which i named tableCellView :

         nodeViews: {
            (my other custom node views...)
            table_cell(node, view, getPos) {
              return new tableCellView(node, view, getPos, mySchema, DOMParser, DOMSerializer);
            },
          },

I need to display the original related node content (node.content.content) which comes as an array of nodes. For this purpose, i used the DOMSerializer to serialize the content and then i append the dom fragment in the node view dom element.

This is my custom node view:

class tableCellView {
  constructor(node, view, getPos, mySchema, DOMParser, DOMSerializer) {
    const outer = document.createElement('td');
    outer.classList.add('tableCellViewCls');
    const colwidth = node.attrs.colwidth;
    if (colwidth) {
      outer.setAttribute('data-colwidth', [0]);
    }
    const inner = document.createElement('p');
    inner.setAttribute('contenteditable', true);
    inner.classList.add('tableCellViewContentCls');
    const fragment = DOMSerializer.fromSchema(mySchema).serializeFragment(node.content.content);
    inner.appendChild(fragment);
    outer.appendChild(inner);
    vm.dom = outer;
  }
  stopEvent(ev) {
    return true;
  }
  update(node, decorations) {
    return false;
  }
}
export default tableCellView;

Everything is fine with this except with nodes to which are attached other node views.

The serialization of such as nodes is based only on their toDom() functions and doesn’t consider their related node views.

Is it possible to get those nodes serialization based on their related node views instead ?

Yes, this is by design. A serializer doesn’t even have access to node views, since those aren’t associated with the actual document, only a thing you can attach to an editor to influence the rendering of these nodes.

You can customize how a DOMSerializer serializes nodes by creating one with a non-default configuration, if putting the serialization you want in your nodes’ toDOM isn’t practical.