Why typeListToArraySnapshot function will change pluginState.type of y-sync plugin

I used PerManentuserdata API,
I want to use TypelistToarraysnapshot to calculate YCHANGE for YXMLFRAGMENT instances to calculate the list of user lists of added and removed. I delete the logic of Dispatch to update View.

I just want to know who modified document.

But I found that the typeListToArraySnapshot function will modify editor view after the traversing. I don’t know what happened.

So i use lodash 中的 cloneDeep 方法来对 sync plugin 的state中的type进行克隆,这样确实有时候会好,但是刚刚出现了这样的问题

lodash.js:3093 Uncaught RangeError: Maximum call stack size exceeded
    at baseGetAllKeys (lodash.js:3093:1)
    at getAllKeys (lodash.js:5916:1)
    at baseClone (lodash.js:2726:1)
    at lodash.js:2733:1
    at arrayEach (lodash.js:530:1)
    at baseClone (lodash.js:2727:1)
    at lodash.js:2733:1
    at arrayEach (lodash.js:530:1)
    at baseClone (lodash.js:2727:1)
    at lodash.js:2733:1

The following is my code

 Y.typeListToArraySnapshot(
  cloneDeep(pluginState.type),
  new Y.Snapshot(oldSnapshot.ds, curSnapshot.sv)
).map((t) => {
  // eslint-disable-next-line no-underscore-dangle
  if (!t._item.deleted || isVisible(t._item, curSnapshot) || isVisible(t._item, oldSnapshot)) {
    return createNodeFromYElement(
      t,
      this.editor.view.state.schema,
      new Map(),
      curSnapshot,
      oldSnapshot,
      computeYChange
    );
  }
  return null;
});

Maybe it is because YXMLFRAGMENT is too deep, will this have anything to do with the closing of the GC?

I set up GC as false, because I want to capture who deleted data.

Hi @Young6118,

Yjs-types are not JSON-objects that you can clone. There are cyclic references that lodash can’t handle, hence you get the mentioned error.

Thank you for your answer, the two -way linked list is really difficult to handle.

But I have a task to compare the difference between the two snapshots now, in order to know who modified the document during the time.

So i cloned YJS-Types by using lodash.

Do you have any better way to let me know who modified the article?

Thank you very much for your answer, do you have any better way to let me know who modified the article?

Hello, very sorry to disturb you.
Do you have any better way to let me know who modified the article?