This.nodes[] is not a function for wrapping list nodes

Hello there!

I have a schema with some list nodes similar to the following:

const schema = new Schema({
    nodes: {
        doc: {
            content: "editorHeader editorBody"
        editorHeader: {
          // ...
        editorBody: {
            content: "body+",
            defining: true,
            isolating: true,
            toDOM: () => ['article', 0],
            parseDOM: [{ tag: 'article' }]
 // Some other probably unrelated stuff in between
        paragraph: {
            content: "inline*",
            group: "body",
            toDOM: () => ["p", 0],
            parseDOM: [{ tag: "p" }]
        ordered_list: {
            group: "body",
            content: "list_item+",
            attrs: { order: { default: 1 } },
            parseDOM: [{
                tag: "ol", getAttrs(dom: HTMLElement) {
                    return { order: dom.hasAttribute("start") ? +dom.getAttribute("start") : 1 };
            toDOM(node) {
                return node.attrs.order == 1 ? ["ol", 0] : ["ol", { start: node.attrs.order }, 0];
        bullet_list: {
            group: "body",
            content: "list_item+",
            parseDOM: [{ tag: "ul" }],
            toDOM() { return ["ul", 0]; }
        list_item: {
            content: "paragraph (ordered_list | bullet_list)*",
            parseDOM: [{ tag: "li" }],
            toDOM() { return ["li", 0]; },
            defining: true

Now, attempting wrap some text in any list node with this schema results in the following error:

index.js:3284 Uncaught TypeError: this.nodes[] is not a function
    at _DOMSerializer.serializeNodeInner (index.js:3284:99)
    at index.js:3276:34
    at _Fragment.forEach (index.js:255:13)
    at _DOMSerializer.serializeFragment (index.js:3250:18)
    at nodeToElement (utils.ts:156:52)
    at update (leaf.editor.svelte:225:39)
    at LeafNodeView.update (leaf.nodeview.ts:170:34)
    at CustomNodeViewDesc.update (index.js:1500:36)
    at ViewTreeUpdater.updateNextNode (index.js:1809:37)
    at index.js:1305:30

However replacing doc’s content property with editorHeader body+ corrects the issue and works as expected. I don’t mind using this approach, the main issue I face is that I have a custom NodeView for editorBody which includes some custom rendering for the children of that node and some styles and I wouldn’t want to get rid of all of that without exhausting all other possible solutions.

All other input rules for blockquotes, paragraph etc., nodes work just fine, it’s just list nodes which have this issue.

I would appreciate any help fixing the issue, thank you!

This sounds like the node on which it crashes is editorBody (you could debug to confirm this)… but that node does have a toDOM property in its spec, which is where DOMSerializer.nodes.editorBody would normally come from. Are you defining a custom serializer for your editor? Or maybe defining multiple shemas and using the wrong one somewhere?

editorBody is exactly where the crash occurs, because its removal from the schema and/or the doc content results in the normal and expected behaviour of lists.

I’m using the default ProseMirror serializer, but the only place I explicitly use the serializer is to convert editorBody’s ProseMirror node into a native DOM element so I can output an HTML string from the node. That method is called during editorBody’s NodeView update method. Further testing just now confirmed that when I remove the function which uses the serializer, wrapping lists working perfectly fine, so I do suspect now that it has something to do with serialization.

How would I go about debugging ProseMirror and triggering the toDebugString methods in the NodeSpec? Maybe that could help find traces of what’s happening

The information below is likely not necessary but just to answer the rest of your question:

The only the time I had used a different schema was the one provided by the prosemirror-schema-basic and extending that with the addListNodes method from the prosemirror-schema-list to compare the differences in behaviour between my custom schema and the basic schema where I had seen it work on the ProseMirror website’s example editor. That’s how I discovered that editorBody was the cause of the issue because that was the only thing in my schema preventing it from essentially being identical to the basic schema, and I did eventually remove all instances of the basic schema from my code.

Just to update, the issue seems to have been resolved completely. This was happening in a HMR dev environment and after removing all instances of the basic schema, the dev environment hadn’t refreshed and was using the old schema under the hood so the issue didn’t resolve unless I hard refreshed the page and the whole development environment.

Thank you for your help!