Hi,
While merging two documents, is it possible to force yjs to pick change from one document over the other? I tried setting clientID of document I want to take precedence to a higher value than that of the other. But it doesn’t seem to consistently work. Is there a way force it?
thanks,
raine
November 17, 2023, 10:16pm
#2
If it’s possible, it would involve a change to the core integrate
method. Probably around here:
while (o !== null && o !== this.right) {
itemsBeforeOrigin.add(o)
conflictingItems.add(o)
if (compareIDs(this.origin, o.origin)) {
// case 1
if (o.id.client < this.id.client) {
left = o
conflictingItems.clear()
} else if (compareIDs(this.rightOrigin, o.rightOrigin)) {
// this and o are conflicting and point to the same integration points. The id decides which item comes first.
// Since this is to the left of o, we can break here
break
} // else, o might be integrated before an item that this conflicts with. If so, we will find it in the next iterations
} else if (o.origin !== null && itemsBeforeOrigin.has(getItem(transaction.doc.store, o.origin))) { // use getItem instead of getItemCleanEnd because we don't want / need to split items.
// case 2
if (!conflictingItems.has(getItem(transaction.doc.store, o.origin))) {
left = o
conflictingItems.clear()
}
It is doing clientId comparisons in at least some of the cases, but I’m not intimate enough with the code to know its behavior in general.
Thanks for your reply Raine. I’ll dig around this part of the code. if it’s not just clientID, it must also be lamport clock.