Extracting and saving data to the yjs document

I am working on a collaborative editor using Tiptap. Inside the editor the user can create a list of tasks. On another page, the user is able to view the task list data outside of the editor, so that means the task data is currently stored both in the yjs document and a separate task table in a database using Graphql. Also, tasks can be changed outside of the editor and those changes are pushed to the yjs document. I have a basic version working, but it relies on me updating the two sources of truth (yjs & the database via graphql) and this causes flickering/race conditions.

Is it possible to use the yjs document as the sole source of truth by saving and extracting information to/from it? Is there a recommended way for getting data from the yjs document to use elsewhere? Any guidance would be greatly appreciated.

1 Like

Hi @laura,

In general, if you want to share information between docs, I recommend to store shared information in a subdocument.

However, y-prosemirror (which is what TipTap uses for synchronization with the ProseMirror editor) does not support subdocuments. You could embed tasks as a ProseMirror View element (I’m sure there is a TipTap API for that) and sync that separately from the main document.

At all costs, you should avoid having two sources of truth. It is impossible to make that work without tradeoffs. You can either make GraphQL the source of truth and sync the changes to a Yjs document (nobody else should be allowed to edit the tasks in Yjs in that case) or the other way around. I don’t think there is another stable workaround that syncs two asynchronous datastores without allowing for dataloss.

1 Like