Closed Dallas62 closed 4 years ago
Same issue here
It does the same thing on the websites live demo (you can see it immediately in the devtools for application/idb, though you need to reload the page to see the text get updated to reflect that the edits were lost).
Since that example is one of the two live demos for the package, it should be pretty easy to use as a test case.
Edit: The error is occurring inside the cleanupDoc function: https://github.com/redgeoff/delta-pouch/blob/257e0c82f7c7e89d5d729c4aced11246caf5a73d/index.js#L215-L226 This function checks whether the new doc has a field that has been set to undefined, but it doesn't check if any of the fields with values have been modified. Only when a field has been set to undefined are the differences between the old and new documents merged, resulting in any updated values to an existing field incorrectly falling through into the "duplicate update" case.
I just try cleanup method on a test database, and it result on a deletion of all updates made.
Exemple:
First doc:
Update 1: prop1 true => false Result a new document:
.all() result:
Execute .cleanup(), .all() result:
And document "Update 1" (123+timestamp) as disappear from database.