Best way to communicate xmlfragment

Hello.
I’m currently working on a asynchronous editor with reviewing functionality (you can imagine github) using blocknote, indexeddb / firestore and of course yjs.
I could implement sending pull request, which stores encoded state as update and communicate in
uint8array.

The problem is about decoding.

when you are writing, we can access xml elements by ydoc.getXmlFragment("document-store").toJSON() given that we are editing on xmlfragment node “document-store”, initialized as follows:

const editor: BlockNoteEditor | null = useBlockNote({
        collaboration: {
            provider,
            fragment: ydoc.getXmlFragment("document-store"),
            user: getRandomUser(),
        },
    });

we can get out of it something like '<blockgroup><blockcontainer backgroundColor="default" id=..., which I can parse now into a neat js object for a viewer.

However, after sending and receiving the ydoc as a state, node pointer disappears and I have no way to access the xmlfragment (“document-store”), which also hinders accessing the xml string.

you can see my code on github

Thanks!

I tried lib0 library (though I cannot still not wrap my head around)

const u8a = new Uint8Array(atob(data.state).split('').map(char => char.charCodeAt(0)));
const decoder = createDecoder(u8a)
const length = readVarUint(decoder);
console.log(readVarString(decoder))
for (let i = 0; i < length; i++) {
    // console.log(read??? Idonno)
}

and also not reading xml and reading directly from indexeddb through provider (so same as the Editor)

const editor: BlockNoteEditor | null = useBlockNote({
        collaboration: {
            provider,
            fragment: ydoc.getXmlFragment("document-store"),
            user: getRandomUser(),
        },
    });

both of which found to be not working properly.

Once you sync the document from wherever it is persisted, you can access its shared types, e.g. ydoc.getXmlFragment("document-store"). Providers typically have a synced event you can wait for.