(bug): Check if structs are empty before findIndexSS and writing encoding.

This commit is contained in:
Siddhartha 2023-11-25 13:23:10 -08:00 committed by GitHub
parent 28ccd5e0dd
commit 058e93d191
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -194,14 +194,16 @@ export const createDocFromSnapshot = (originDoc, snapshot, newDoc = new Doc()) =
getItemCleanStart(transaction, createID(client, clock)) getItemCleanStart(transaction, createID(client, clock))
} }
const structs = originDoc.store.clients.get(client) || [] const structs = originDoc.store.clients.get(client) || []
const lastStructIndex = findIndexSS(structs, clock - 1) if(structs.length != 0) {
// write # encoded structs const lastStructIndex = findIndexSS(structs, clock - 1)
encoding.writeVarUint(encoder.restEncoder, lastStructIndex + 1) // write # encoded structs
encoder.writeClient(client) encoding.writeVarUint(encoder.restEncoder, lastStructIndex + 1)
// first clock written is 0 encoder.writeClient(client)
encoding.writeVarUint(encoder.restEncoder, 0) // first clock written is 0
for (let i = 0; i <= lastStructIndex; i++) { encoding.writeVarUint(encoder.restEncoder, 0)
structs[i].write(encoder, 0) for (let i = 0; i <= lastStructIndex; i++) {
structs[i].write(encoder, 0)
}
} }
} }
writeDeleteSet(encoder, ds) writeDeleteSet(encoder, ds)