I’m new to Yjs, and I’m building a collaborative editor using Tiptap and Yjs. Since I have a database limitation that prevents me from storing Yjs directly, I’m storing the JSON output (achieved with
editor.getJSON()) in my database. However, when I load the data back during the initial load, I’m encountering a problem with data duplication during the merge. Here’s an overview of my process:
- Whenever a user makes an edit, I capture the JSON representation and send it to the backend. This JSON data is then saved to the database, and I also broadcast the update to other users using a Uint8Array.
- When other users receive the update, I use
Y.applyUpdate(yDoc, updates)to merge the changes.
The issue is that during the initial merge, the data gets duplicated. Subsequent merges work perfectly. What could be causing this initial duplication, and how can I ensure that the initial merge works correctly?