-
-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Content resent after hocuspocus server restarts #84
Comments
Hey Zeljko. Thank you so much for your bug report. Can you share your backend/hocuspocus code as well? |
Do you use the const hocuspocus = Server.configure({
async onCreateDocument(data) {
const fieldName = 'default'
// Check if the given field already exists in the given document.
// Important: Only import a document if it doesn't exist in the primary data storage!
if (data.document.isEmpty(fieldName)) {
return
}
// import the document from somewhere else…
return new Doc()
}
} The background is: Serializing the Y-Doc to Prosemirror JSON in the Because saving a Y-Doc with the related collaboration history can be hard, we built the You can read more on the need for a primary storage here: https://www.hocuspocus.dev/guide/documents#using-a-primary-storage |
Hi Kris, here is the collab server code:
It seems that i miss-understood the purpose of the rocksDb, i thought that it can be used instead of PostgreSQL for example (which i am using). I didn't find any tutorial regarding the mix of rocksDb with other databases, that's why i didn't include it and used PostgreSQL directly (is that wrong?). Also, i can't find any example how to configure UI for using IndexedDB with v2.. I found in example that it is imported, but not set anywhere (or importing is enough? i was looking https://next.tiptap.dev/examples/collaborative-editing) |
It's not wrong per se, but it will lead to issues like the one you described above. Your setup looks fine, just include the rocksdb extension and it should work. :) Theoretically, you could also store the collaboration history in your PostgreSQL database, but it's hard. Especially because there is no documentation at the moment on how to do it. We ourselves just kinda brute-forced our implementation: https://docs.yjs.dev/tutorials/persisting-the-document-to-a-central-database
I recently removed the indexedDB from tiptaps collaboration example because we had some issues with it and hocuspocus. Long story short: We completely changed how hocuspocus worked a few weeks back and it resulted in corrupted data which was stored in the clients indexeddb and completely destroyed our collab-system because Y-js always wanted to merge the corrupted data… So, nothing to worry about for you! It's pretty simple to set up, just import it, create a new instance and pass it the Y-Doc: import { IndexeddbPersistence } from 'y-indexeddb'
const ydoc = new Y.Doc()
const indexdb = new IndexeddbPersistence('tiptap-collaboration-example', ydoc) |
One comment on your implementation: async onChange(data) {
const save = async () => {
// ...
}
// you can remove this, it's basically the same as this._debounced?.clear()
if (this._debounced) {
this._debounced.clear();
}
this._debounced?.clear();
this._debounced = debounce(() => save, this._debounceTime);
this._debounced();
// debouncing is meant to take load off your database server
// calling save here directly will just make the whole debouncing useless
save();
} |
Make sure to use the latest version of |
Hi Kris, It works very good now! Thank you for suggestions! |
Very nice! I'm happy it works now. 🙌 |
Hi,
I occurred one more issue during collaboration setup :/ After hocuspocus restarts, existing content from tiptap v2 is sent again, which results doubling the data in the content.
Steps to reproduce:
Error: Front end sends 'Test' content again to hocuspocus, which results with two 'Test' content paragraphs in database / file.
NB: After you restart it again, two 'Test' paragraphs will be sent, which results with 4 'Test' items in the database..
Front end is configured in the following way:
Thank you for help in advance!
The text was updated successfully, but these errors were encountered: