Repository navigation
Description
Description
Pages created from a template sometimes show the whole content twice after reopening them. Every heading and block is duplicated. This happened to two different users in our workspace.
The root cause is not template specific. It affects every page that has content but no ydoc in the database.
Steps to reproduce
- Self-hosted Docmost v0.97.0 (Docker image
docmost/docmost:latest,pgvector/pgvector:pg18-bookworm,redis:8) - Create a new page from a template
- Leave the page without editing it
- Open the page again in the same browser
- The content is now duplicated
Logs
Example page 01a18698-ed11-7a77-9485-53c6122b5c13:
07:38:51.727 PersistenceExtension converting json to ydoc: 01a18698-ed11-...
07:39:17.942 CollabLoggerExtension Unloaded page.01a18698-ed11-... from memory
(no "Page updated" in between)
07:42:00.802 PersistenceExtension converting json to ydoc: 01a18698-ed11-...
07:42:10.860 PersistenceExtension Page updated: 01a18698-ed11-... <- duplicated content saved
Pages created empty (creating fresh ydoc) are not affected.
Cause
apps/server/src/collaboration/extensions/persistence.extension.ts
onLoadDocumentbuilds a ydoc frompage.contentwhenpage.ydocis null, but never persists it. The result ofY.encodeStateAsUpdate(ydoc)is discarded.onStoreDocumentreturns early when the JSON equalspage.content. For an unchanged page created from a template the ydoc is therefore never written.- On the next cold load the server builds a second, independent ydoc from the same JSON.
- The browser still holds the first Yjs state in IndexedDB (
page-editor.tsx,IndexeddbPersistence). When both states sync, Yjs treats them as separate inserts and the content ends up twice. This merged state is then persisted.
The same logic exists in v0.96.0, so this is not a v0.97.0 regression.
Suggested fix
Persist the converted state directly in onLoadDocument:
if (page.content) {
this.logger.debug(`converting json to ydoc: ${pageId}`);
const ydoc = TiptapTransformer.toYdoc(
page.content,
'default',
tiptapExtensions,
);
- Y.encodeStateAsUpdate(ydoc);
+ try {
+ await this.pageRepo.updatePage(
+ { ydoc: Buffer.from(Y.encodeStateAsUpdate(ydoc)) },
+ pageId,
+ );
+ } catch (err) {
+ this.logger.error(`Failed to persist initial ydoc for ${pageId}`, err);
+ }
+
return ydoc;
}This also covers the case where a page is opened and left without any edit, so onStoreDocument never has a reason to save.
Alternatively /templates/use (and any other path that creates pages with JSON content only) could store the ydoc together with the content.
Workaround
Make a lasting edit (e.g. fill in a field) and wait for the first save before leaving a page created from a template. Typing and deleting again does not help, since the content is then identical to the template and nothing is stored.
Activity
Philipinho commentedon Oct 30, 2026
Thanks for reporting. A fix will be available in the next release.