Y-prosemirror - yDocToProsemirrorJSON root node type is always 'doc'

Our prosemirror schema uses a root node type of 'root' and then a single child 'document' (helps us with our Tiptap editor when storing document level attributes).

When calling yDocToProsemirrorJSON on our document, the root node type returned is hardcoded to 'doc'. (https://github.com/yjs/y-prosemirror/blob/master/src/lib.js#L304-L307)

Is this intentional?

Or could this simply be updated to:

return {
  type: item.type,
  content: items.map(serialize)

From a prosemirror perspective, that does seem like a bug since the topNode can be something else than "doc". Unsure if item.type works though because item isn’t defined in that context.

Edit: Looks like to resolve this issue, y-prosemirror/lib would have to be modified to use Y.XmlElement instead of Y.XmlFragment since Y.XmlElement defines a nodeName (and allows for top level attrs) and Y.XmlFragment does not.

1 Like