I was wondering if there is a way of getting this data from the API, convert it into a y.js document and attempt to merge with the document from y.js.
A Yjs document is like a git repository with a change history. Yjs itself doesn’t calculate a diff with remote versions of the document. It’s really just a change history. So no, that’s not possible…
I don’t see any alternative since we technically have 2 sources of truth.
This seems to be a common denominator between these questions.
You can’t really have two sources of truth unless you can devise an algorithm to sync them (it’s not that trivial). Similarly, there is no viable algorithm that syncs a git repository with a mercurial repository (I mean, many have tried, but it never worked out).
My suggestion is that you use Yjs as the source of truth and reflect the changes to the database.
Anything else will likely be buggy. Give me an algorithm, and I’ll break it.
In every task and projekt the user is able to edit a note that is a TipTap-editor powered by y.js.
All the Dexie data is synced and stored in the local indexeddb but the y.js data is not. y.js data is only stored if accessed on this device first.
What happens when two users open the same task at the same time? It will likely duplicate as well, because Yjs doesn’t merge, it just manages a change history.
Second option: Give the user a blank editor that later is merged when online
That works, but it would be sad if your app wouldn’t work offline anymore.
My suggestion is to store Yjs docs directly in Dexie. That is certainly possible. Maybe have a look at y-indexeddb and the document-updates section in the docs