Nested YXmlElements in ypy

I’m using Ypy to construct a YDoc in python that I saved with encodeStateAsUpdate in node with yjs. There might be something obvious that I’m missing but in python nested xmlelement get converted to xmltext (only the top level xmlelement is an actual xmlelement with children, the rest get flattened).

I can’t tell if this is:
a) some limitation in yrs (seems kind of unlikely)
b) some limitation in ypy (more likely?)
c) some failure on my end (most likely, but haven’t found an issue yet, some code below, which is pretty straightforward I think).
d) v1 vs v2 issue? though I’m pretty sure encodeStateAsUpdate uses the v1 encoder, which python/yrs assumes, so it shouldn’t be that

res = cur.execute("select contents from files where id = 178")
(contents,) = res.fetchone()
doc = YDoc()
Y.apply_update(doc, contents)
        await db("files")
          .update({ contents: Y.encodeStateAsUpdate(ydoc), updatedAt: new Date() })
          .where("id", docId);

Also as this is my first post in this community, just wanted to say Yjs is awesome, having a great time exploring and learning more about it

ok went down to yrs and applied the update directly, and it seems that yrs doesn’t handle the nested YXmlElements either, though it successfully decodes the nested inserts that /should/ lead to nested YXmlElements

I also managed to construct nested YXmlElements with ypy, so the issue is not that ypy/y-crdt cannot support the structure, but that the updates seem to be lossy, ie they flatten nested structures into YXmlText’s somewhere

Ok for anyone coming across this with a similar issue, the “problem” seems to be that @slate-yjs doesn’t actually use YXmlElements to encode the structure of the document, but instead somehow encodes children in the YText update?

the plot thickens. So slate-yjs uses embedded yxmltexts instead of yxmlelements with children, and I believe that I can’t currently access those embedded texts via the python/yrs interface, even though it seems to understand nested elements

Oh yeah, I remember. slate-yjs represents the data in a YText type with embeds that are types (other editor bindings only use Y.Xml). In order to read it you need to understand how to read YText types that have embeds. Try ytext.toDelta(). You probably have to call on each individual embed-child of Y.Text again.

I think the easiest way would be to instantiate an editor on the backend when you want to read the data. Then you can read the document using the Slate API.