Open LT1211 opened 9 months ago
i am using hocuspocus as backend server, and here is my solution to fix the issue
const insertRst = await collection.insertOne(
{
rid: documentName,
data: data.toString('base64'),
create_at: Date.now(),
},
{}
);
const fromBase64 = (str: string): Uint8Array =>
new Uint8Array(Array.from(atob(str)).map((char) => char.charCodeAt(0)));
async onLoadDocument(data) {
if (data.document.isEmpty('content')) {
const result = await selectYjsDocument(data.documentName);
if (result) {
Y.applyUpdate(
data.document,
fromBase64(result),
'snapshot-patch'
);
}
}
return data.document;
}
If hocuspocus is using sqlite - it would empty its local db on server restart, then pull the content from your remote server.
In this case it would think the document is empty and insert the remote content again, then serve that to the client, which also has the content in indexeddb. This would result in dupe content.
if you're using sqlite, try switching to a db that wont get wiped on server restart
Hi @BitPhinix
I have a similar issue when using slate-yjs with y-indexeddb. Each time the slate editor is mounted, the contents are duplicated. The indexeddb updates table also seems to double in size each time the page is loaded. I'm not doing anything special here. Just passing along the y doc which holds my sharedType...
This is frontend code
This is backend code