From 49cdd396171569c0079e84b7d6f84a765431ebfa Mon Sep 17 00:00:00 2001 From: Zaid Humaimidi Date: Wed, 12 Feb 2025 19:05:08 -0800 Subject: [PATCH] Fix (de)serialization bug in VersionedMap --- lib/versioned-map.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/versioned-map.ts b/lib/versioned-map.ts index 2babcf6..88076bf 100644 --- a/lib/versioned-map.ts +++ b/lib/versioned-map.ts @@ -112,6 +112,8 @@ export default class VersionedMap { prev = v; } + if (prev === NONEXISTENT && !res.delete) return null; + return res; } @@ -122,6 +124,8 @@ export default class VersionedMap { del, ); + if (!mutations) return; + const revisions = []; let prev: V | symbol = NONEXISTENT; @@ -149,7 +153,7 @@ export default class VersionedMap { public *diff(): IterableIterator<[K, V, V]> { for (const [key, revisions] of this.map) { - if (revisions.length === 1) continue; + if (revisions.length <= 1) continue; let first = revisions[0]; let last = revisions[revisions.length - 1]; if (first === NONEXISTENT && last === NONEXISTENT) continue;