Attribution of changes

I’m developing an application where I need to calculate the user that last edited a particular piece of content (eg a paragraph). I understand that this information isn’t strictly stored in the CRDT, for the purposes of this app the last user that the central source of truth received is a good enough estimate.

I was thinking I can hook into either afterTransaction or update on the server to record changes as they come in. Which would be more appropriate?

With afterTransaction I’m finding it very difficult to determine which user actually performed the change in the transaction. Looking for ideas on approach, I’ve been banging my head on this for a while.


I was thinking about the same feature.
As far as I found out, some applications store this information as an attribute inside an editor node.

For example in ProseMirror:
You could create a prosemirror plugin that appends to every prosemirror transaction an update step where you update the attributes of all changed nodes.

The html node could then look like the following:
(here you see only the data-author-id and data-created-at. But you could extend it with a last updated field)

It is nothing that I was able to implement yet, just some things I found and thought about.
Maybe this could also solve the problem. But unfortunately this is not a yjs solution…

Yes, you could go this approach but it’s duplicating data that already exists in the document, as every operation is mapped to a clientId in the yjs doc already. I think this is a good fallback solution

I like @flow’ solution. This is probably the best solution if you only want to store the latest information of who edited which paragraph.

Each paragraph has a unique ID that you could access using You could use that unique ID instead of the GUID that you are generating for each div. Furthermore, you could maintain a separate map that maps the unique id’s of the paragraphs to the user that last-edited the paragraph. This would also allow you to assign additional information to the last-edited paragraph.

What about something like a git blame, where you keep the entire history of who edited a paragraph or textblock? It’d be cool if you could see a document history, either by tracing all edits made by a single ‘contributor’ or by all edits made to a specific block inside a larger document.

Hi @bhl,

This is basically what the versioning approach and PermanentUserData are about. PermanentUserData efficiently tracks every change made by a user. Some editor-bindings support rendering that information. E.g.

It would easily be possible to select a range of text and find out who created that text. Using the versioning approach you can find out about the editing-history.

1 Like

I’m using Prosemirror, so in order to achieve this it would probably be best done via a prosemirror plugin that writes the user id as an attribute on the node whenever edited. It feels “hacky” and duplicative to my mind, but it does have the advantage of being very understandable for folks that maintain the code in the future.

That sounds like a good solution. I like the clean separation.