From f1ab41757046b5240f6ac827c2881073c20ad1c6 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Thu, 23 Sep 2021 22:14:29 +0200 Subject: [PATCH] mergeUpdates on array with single entry just returns the first entry --- src/utils/updates.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/updates.js b/src/utils/updates.js index afbae0cc..97b67a58 100644 --- a/src/utils/updates.js +++ b/src/utils/updates.js @@ -287,6 +287,9 @@ const sliceStruct = (left, diff) => { * @return {Uint8Array} */ export const mergeUpdatesV2 = (updates, YDecoder = UpdateDecoderV2, YEncoder = UpdateEncoderV2) => { + if (updates.length === 1) { + return updates[0] + } const updateDecoders = updates.map(update => new YDecoder(decoding.createDecoder(update))) let lazyStructDecoders = updateDecoders.map(decoder => new LazyStructReader(decoder, true)) @@ -312,8 +315,9 @@ export const mergeUpdatesV2 = (updates, YDecoder = UpdateDecoderV2, YEncoder = U if (dec1.curr.id.client === dec2.curr.id.client) { const clockDiff = dec1.curr.id.clock - dec2.curr.id.clock if (clockDiff === 0) { + // @todo remove references to skip since the structDecoders must filter Skips. return dec1.curr.constructor === dec2.curr.constructor ? 0 : ( - dec1.curr.constructor === Skip ? 1 : -1 + dec1.curr.constructor === Skip ? 1 : -1 // we are filtering skips anyway. ) } else { return clockDiff