Skip to content

Commit 739fff6

Browse files
committed
fix: fixes InvalidSignature errors that could happen during streaming
1 parent ffebb4f commit 739fff6

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

packages/cojson/src/storage/storageAsync.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ export class StorageApiAsync implements StorageAPI {
298298

299299
const actuallyNewTransactions = newTransactions.slice(actuallyNewOffset);
300300

301+
if (actuallyNewTransactions.length === 0) {
302+
return sessionRow?.lastIdx || 0;
303+
}
304+
301305
let newBytesSinceLastSignature =
302306
(sessionRow?.bytesSinceLastSignature || 0) +
303307
actuallyNewTransactions.reduce(

packages/cojson/src/storage/storageSync.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ export class StorageApiSync implements StorageAPI {
279279

280280
const actuallyNewTransactions = newTransactions.slice(actuallyNewOffset);
281281

282+
if (actuallyNewTransactions.length === 0) {
283+
return sessionRow?.lastIdx || 0;
284+
}
285+
282286
let newBytesSinceLastSignature =
283287
(sessionRow?.bytesSinceLastSignature || 0) +
284288
actuallyNewTransactions.reduce(

packages/cojson/src/storage/syncUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ export function collectNewTxs({
2323
if (!sessionEntry) {
2424
sessionEntry = {
2525
after: firstNewTxIdx,
26-
lastSignature: "WILL_BE_REPLACED" as Signature,
26+
lastSignature: signature,
2727
newTransactions: [],
2828
};
2929
contentMessage.new[sessionRow.sessionID] = sessionEntry;
30+
} else {
31+
sessionEntry.lastSignature = signature;
3032
}
3133

3234
for (const tx of newTxsInSession) {
3335
sessionEntry.newTransactions.push(tx.tx);
3436
}
35-
36-
sessionEntry.lastSignature = signature;
3737
}
3838

3939
export function getDependedOnCoValues(

0 commit comments

Comments
 (0)