Error: Garbage-collection must be disabled in `originDoc`!

when I use this code to recover snapshot:

ydoc.on('update', (update, origin) => {
        try {
            let snapshot = Y.snapshot(ydoc);
            let snap: Y.Doc = Y.createDocFromSnapshot(ydoc, snapshot);
            console.log("snapshot:" + JSON.stringify(snapshot));
            let params = {
                file_id: editorAttr.docId,
                project_id: editorAttr.projectId,
                content: ytext.toString(),
                snapshot: JSON.stringify(snapshot)
        } catch (e) {

catched this error:

Error: Garbage-collection must be disabled in `originDoc`!
    at Module.createDocFromSnapshot (chunk-4EIPJV5U.js?v=8ac15dea:2292:11)
    at CollarEditorService.ts:238:33
    at chunk-4EIPJV5U.js?v=8ac15dea:138:83
    at Array.forEach (<anonymous>)
    at _Doc.emit (chunk-4EIPJV5U.js?v=8ac15dea:138:68)
    at cleanupTransactions (chunk-4EIPJV5U.js?v=8ac15dea:2638:16)
    at transact (chunk-4EIPJV5U.js?v=8ac15dea:2690:9)
    at _YArray.push (chunk-4EIPJV5U.js?v=8ac15dea:4399:7)
    at chunk-4EIPJV5U.js?v=8ac15dea:2005:31
    at Map.forEach (<anonymous>)

why did this happen and what should I do to fixed this issue?

The Doc has to be created with gc disabled for snapshots to work:

const doc = new Y.Doc({ gc: false });
1 Like