Retrieving TipTap JSON state from Y.Doc


I am a college undergrad using TipTap+y-websocket for a project. I was successful in setting up persistence using the bindState and writeState interfaces. Since I am persisting the Y.Doc in my database, I need to recover the TipTap’s JSON state from the Y.Doc for server-side processing.

I tried using yDocToProseMirrorJSON from y-prosemirror but it returns the following JSON:

{ type: 'doc', content: [] }

I narrowed it down to .toArray method within the function’s implementation returning an empty array.
I use the following to reinitialize my Y.Doc with the persisted state:

loadFromDatabase().then(data => {
  const ydoc = new Y.Doc;
  Y.applyUpdate(ydoc, data); // I persist data using Y.encodeStateAsUpdate(ydoc) in writeState()
  console.log(yDocToProseMirrorJSON(ydoc)); // returns the empty json above

How may I access the JSON state from the Y.Doc? I need to recover it server-side in a NodeJS environment and not client-side.

I wasn’t able to find anything similar on the forum. I would appreciate any help regarding the same.

Thank you for your help.

Update: managed to figure it out. Posting if anyone else faces this issue.
Looking at the signature of the yDocToProseMirrorJSON function, I saw that it takes an optional second argument specifying the name of the Y.xmlFragment, defaulting to “prosemirror”. In my case, my documents were being synced using a top-level Y.Doc, in which case the contained xmlFragment were mapped to “default”. Supplying this as the second argument fixed it :slight_smile:

1 Like