How to equality check b/w two Yjs docs

Hi All,

I’m new to Yjs, and trying to figure out What’s the best way to perform equality checks b/w two Y.Doc()? I want to compare Yjs doc in the user request with the saved one in the database and save the new one only if there’s a change.

Should I convert both to

  • toJSON and compare?
  • encodeStateVector and compare?
  • create snapshots and compare using Y.equalSnapshots?

and if ther’s change then

Y.applyUpdate(savedDoc, Y.encodeStateAsUpdate(req.document))
saveToDB(savedDoc)

Hi @santhosh-ps,

Y.equalSnapshots is currently the best approach :+1:

1 Like

If I make changes to document, and then undo those changes, equalSnapshots still sees my document is not equal to the original version. Is that expected?

I am using Tiptap as my editor, FYI.