Problem with dom inserted programmatically in an empty parent

Hi,

i defined a Node type “list” which has a content spec “item*”, and a Node type “item”. When i do this:

  • add a list node to the doc, using transform methods
  • then later add an item DOM node into the empty DOM list node (using pure DOM functions)

The item is not inserted where expected. Instead, a new “list” node is created before the actual list node, and the item is inserted there.

If i change the spec to be “(paragraph | item)+”, the item is appended as expected. I suspect there is some kind of bug there, but i’m not sure where to start digging.

Could you condense this to a simple example script that allows me to reproduce it?

This is an attempt at a minimal example: https://github.com/kapouer/prosemirror-sample though i’m still working on it, because right now i can only show a problem when items are leaf nodes.

I’ve been surprised by the order of declaration of the nodes spec. Defining nodes.item before nodes.list solved the problem i had…

It looks like the issue is that ParseRule.attrs doesn’t do what you think it does – it doesn’t match DOM attributes, but rather provides the attributes for the resulting ProseMirror node. As such, your two parse rules for <div> elements match the same DOM nodes, and you probably want something like tag: "div.item" instead.

Thanks for pointing that out, i fixed the example. Now i think i reproduced the exact problem i had. When an item is appended to a list, a new list is created before.

Ok i found my mistake: i changed the DOM in a way that prosemirror cannot track. Apologies !

Actually i’m still in the dark. In the example i gave it works all right, and in the real-world code i’m using i do still need to give some default content to the list to make sure it can be filled later, or else the list is duplicated as if it wasn’t found. I’ll report here later if i find what is going on.