Skip to content

Commit 11ad749

Browse files
committed
Do not emit conflict events for mutual deletions
No changes can be lost when documents are deleted on both ends
1 parent 098962d commit 11ad749

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

src/sync.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,19 @@ export class Sync {
507507
node = mergeMutualDeletion(node);
508508
delete node.remote;
509509
} else if (node.remote.body !== undefined) {
510-
log('[Sync] Emitting conflict event');
511-
setTimeout(this.rs.local.emitChange.bind(this.rs.local), 10, {
512-
origin: 'conflict',
513-
path: node.path,
514-
oldValue: node.local.body,
515-
newValue: node.remote.body,
516-
lastCommonValue: node.common.body,
517-
oldContentType: node.local.contentType,
518-
newContentType: node.remote.contentType,
519-
lastCommonContentType: node.common.contentType
520-
});
510+
if (node.remote.body !== false && node.local?.body !== false) {
511+
log('[Sync] Emitting conflict event');
512+
setTimeout(this.rs.local.emitChange.bind(this.rs.local), 10, {
513+
origin: 'conflict',
514+
path: node.path,
515+
oldValue: node.local.body,
516+
newValue: node.remote.body,
517+
lastCommonValue: node.common.body,
518+
oldContentType: node.local.contentType,
519+
newContentType: node.remote.contentType,
520+
lastCommonContentType: node.common.contentType
521+
});
522+
}
521523

522524
if (node.remote.body === false) {
523525
node.common = {};

test/unit/sync.test.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,28 @@ describe("Sync", function() {
949949
}, 20);
950950
});
951951
});
952+
953+
describe("when node was also deleted on remote", function() {
954+
beforeEach(function() {
955+
this.emitChange = sinon.spy(this.rs.local, "emitChange");
956+
957+
this.rs.sync.autoMergeDocument({
958+
path: "foo",
959+
common: { body: "foo", contentType: "bloo", revision: "common" },
960+
local: { body: false },
961+
remote: { body: false }
962+
});
963+
});
964+
965+
it("does not emit a conflict event", function(done) {
966+
expect(this.emitChange.called).to.be.false;
967+
968+
setTimeout(() => {
969+
expect(this.emitChange.called).to.be.false;
970+
done();
971+
}, 20);
972+
});
973+
});
952974
});
953975

954976
describe("#autoMergeFolder", function() {

0 commit comments

Comments
 (0)