Parsing JSON to HTML produces error

Hi!

We’re storing both the JSON content from the editor and the schema (as JSON) in our database and want to be able to display it as HTML. However, I’m getting the following error when trying to parse the JSON using DOMSerializer:

vue.runtime.esm.js:8451 TypeError: this.nodes[node.type.name] is not a function
    at DOMSerializer.serializeNode (vue.runtime.esm.js:8451)

The code I’m using to parse the content is as follows:

function parseJson(content, schemaJSON) {
    const div = document.createElement('div');
    const schema = new Schema(schemaJSON);
    const contentNode = Node.fromJSON(schema, content);
    const fragment = DOMSerializer.fromSchema(schema).serializeFragment(contentNode.content);

    div.appendChild(fragment);

    return div.innerHTML;
}

If I switch out the Schema for one imported from prosemirror-schema-basic it works with basic text but our editor has more stuff in it so that won’t work. I’m struggling to find any documentation on how to do this properly. I’m guessing the problem is recreating a schema from JSON. Is there a better way to do this? Or any idea why this isn’t working?

Sounds like some of your schema nodes don’t have a toDOM method in their node specs.