Master Doc Updates can Propogate to Copies

I’d like to know if this is feasible with Yjs.

I’d like to create a master document, then from this master document I would create multiple copies that are edited independently. Would it be possible to then make updates to my master document and capture these operations, then apply the operations to each of the copies?

Here’s a scenario to help understand more specifically the problem I’m trying to solve. Let’s say the master document was a school assignment with questions created by a teacher. This master assignment was then copied for each student. Each student worked independently on answering the questions on their own assignments. Then the teacher noticed a problem with one of the questions and wanted to revise it, but doesn’t want the students to have to start over. The teach wants the revision made on the master document to be applied to all of the copies without interfering with the answers the students have already started writing.

I believe based on what I understood from this post that I should be able to do it, but just wasn’t certain so I wanted to provide a sample use case to be sure.

I think this part of the post is most relevant:

So if you saved the delta from the teacher’s change, or a simple diff, then you could apply it to the copies. In other words, separate Docs (with different guids) are completely separate, so in order to apply some changes from one to another you have to pull them out of the Doc and apply them like a normal user edit.

On a more theoretical level, whether you can merge an upstream document depends how “deep” or “structural” the change is. If the teacher fixed a typo or changed the wording of a question, the student’s response is still valid. If the teacher deletes a question or changes it completely, the student’s response is no longer valid. Each domain has its own concepts of identity and change.

I wonder if your architecture would be easier if you referenced the master document from each student’s work rather than copying it.

Thanks for the reply.

So it would be very similar to multiple devs creating git branches off main, then when changes are merged into main the devs can rebase to pull (play back) the changes into their branch.

So in Yjs when the teacher went to make changes, then I would capture those changes using the toDelta() function of Yjs (Delta Format doc). I would then use the applyDelta() function to try to apply these changes to each of the student assignments. I’m thinking it would be best to capture the teacher changes in small chunks so that I could give immediate feedback if there was a problem applying the delta, or perhaps let the student know the teach made a change to the master that couldn’t be applied and for them to resolve it.

I’m still wondering, if I could assume that that there were no deep or structural changes, would I be able to capture and apply the operations-log changes and apply them to all of the documents? It seems like my risk would be similar to users making edits offline, which we do allow in our app (with a warning).

For my use case right now, referencing the master document from each of the student assignments wouldn’t work. In the future I could use a use for this.

Thanks for your help! We will begin implementing Yjs into our app next week. We use RxDB in our Ionic/Angular app, so it looks like we’ll need to fork and modify the existing IndexedDB provider to work with RxDB. On the backend we store the data in a MongoDB database, so we’ll be able to use the existing provider for it.


Makes sense. YJS doesn’t have an equivalent to rebase. It’s just convergent merges. I guess that would be more like cherry-picking.

I’m not sure what shared types you are using, so it’s hard to comment on the viability of your delta strategy. For a single Y.Text though, it seems doable!

We’ll find out when we start digging in next week. The use case I described is a very desirable feature, but not a required one. If it worked, I think users would absolutely love it!

Thanks for your support!


1 Like