Skip to content

Commit

Permalink
do not save empty updates - fixes yjs#31
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Jun 16, 2023
1 parent 41a5e59 commit 5e0917e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/y-indexeddb.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ export class IndexeddbPersistence extends Observable {
/**
* @param {IDBObjectStore} updatesStore
*/
const beforeApplyUpdatesCallback = (updatesStore) => idb.addAutoKey(updatesStore, Y.encodeStateAsUpdate(doc))
const beforeApplyUpdatesCallback = (updatesStore) => {
const update = Y.encodeStateAsUpdate(doc)
// Uint8Array([0,0]) is an empty update and can be skipped
if (update.length <= 2) return
return idb.addAutoKey(updatesStore, update)
}
const afterApplyUpdatesCallback = () => {
if (this._destroyed) return this
this.synced = true
Expand Down

3 comments on commit 5e0917e

@micrology
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it with PRSM and it works! Thank you.

@raineorshine
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks for testing it out :).

I'll open a PR and see what the big man says. (So far he has ignored the thoroughly researched issue I created... 😑)

@raineorshine
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.