Showing History By User

I would like to be able to show history of a document by user in my application.

  • User A writes a long sentence and finishes before User B
  • User B write a long sentence at the same time
  • Two history items, one for user A and one for user B each with their own update

I wrote some code to debounce the document change events before saving both the YJS state and Delta state to my server.

I do this debounce grouped by user so that I can get the changes attributed to each user.

The problem is if I just store the state of the document when the debounce completes for each user, you could have some changes from user B in the history item for User A because although they stopped first, user B’s content has already been synced to the document.

I solved this by fetch the last state of the YJS document without either of their changes (persisted to the DB) and manually applying the updates for each user individually one after another on a new Doc and persisting that.

This works okay, but I was wondering if there was an easier way to derive the state I want from the YJS Doc on the server without needing to fetch the persisted one from the DB and manually apply the updates that came in.

Thanks in advance!