Closed LT1211 closed 5 months ago
Description I use y-indexedDB and hocuspocus to realize document storage and collaboration, but the document is always empty when the backend is initialized, resulting in default data being added to my yjs document every time I connect.
frontend code
const docName = id || 'slate-yjs-demo' const provider = useMemo( () => new HocuspocusProvider({ url: `ws://127.0.0.1:3000/ws?clientId=${docName}`, name: docName, connect: false }), [] ) const indexedDB = useMemo( () => new IndexeddbPersistence(docName, provider.document), [] ) const editor = useMemo(() => { const sharedType = provider.document.get(docName, Y.XmlText) const e = withReact(withCursors(withYjs(createEditor(), sharedType), provider.awareness as Awareness,{ data: randomCursorData() })) return e }, [provider.awareness, provider.document]) useEffect(() => { provider.connect() return () => provider.disconnect() }, [provider])
backend code
const server = Server.configure({ name: 'hocuspocus-fra1-01', timeout: 30000, debounce: 5000, maxDebounce: 30000, async onLoadDocument(data) { if (data.document.isEmpty(data.documentName)) { const insertDelta = slateNodesToInsertDelta(initialValue) const sharedRoot = data.document.get(data.documentName, Y.XmlText) as unknown as Y.XmlText sharedRoot.applyDelta(insertDelta) } return data.document } })
The document judgment of the backend is always true,Is there something missing?
https://tiptap.dev/docs/hocuspocus/guides/persistence
This is very useful to me, thank you.
Description I use y-indexedDB and hocuspocus to realize document storage and collaboration, but the document is always empty when the backend is initialized, resulting in default data being added to my yjs document every time I connect.
frontend code
backend code
The document judgment of the backend is always true,Is there something missing?