cross-tab-worker-databus 0.20.70 → 0.20.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1417,6 +1417,8 @@ var CrossTabDataBus = class {
1417
1417
  persistenceRetryMaxAttempts;
1418
1418
  persistenceRetryBackoffMs;
1419
1419
  persistenceRetryGeneration = 0;
1420
+ pendingReplayPersistence = [];
1421
+ replayPersistenceFlushScheduled = false;
1420
1422
  replayHydration;
1421
1423
  // Retention cleanup is coalesced so a burst of publications does not issue
1422
1424
  // one IndexedDB read/write transaction per message. The newest cutoff wins.
@@ -2051,12 +2053,28 @@ var CrossTabDataBus = class {
2051
2053
  }
2052
2054
  }
2053
2055
  if (this.replayPersistence) {
2054
- void this.withPersistenceRetry("append", () => this.replayPersistence.append(storedMessage)).catch((error) => this.reportPersistenceError(error));
2056
+ if (this.replayPersistence.appendBatch) {
2057
+ this.pendingReplayPersistence.push(storedMessage);
2058
+ this.scheduleReplayPersistenceFlush();
2059
+ } else {
2060
+ void this.withPersistenceRetry("append", () => this.replayPersistence.append(storedMessage)).catch((error) => this.reportPersistenceError(error));
2061
+ }
2055
2062
  if (this.replayRetentionMs !== void 0 && this.replayPersistence.clearBefore) {
2056
2063
  this.scheduleReplayRetentionCleanup(this.now() - this.replayRetentionMs);
2057
2064
  }
2058
2065
  }
2059
2066
  }
2067
+ scheduleReplayPersistenceFlush() {
2068
+ if (this.replayPersistenceFlushScheduled) return;
2069
+ this.replayPersistenceFlushScheduled = true;
2070
+ queueMicrotask(() => {
2071
+ this.replayPersistenceFlushScheduled = false;
2072
+ const batch = this.pendingReplayPersistence.splice(0);
2073
+ if (batch.length === 0 || !this.replayPersistence) return;
2074
+ const operation = this.replayPersistence.appendBatch ? () => this.replayPersistence.appendBatch(batch) : () => Promise.all(batch.map((message) => this.replayPersistence.append(message))).then(() => void 0);
2075
+ void this.withPersistenceRetry("append", operation).catch((error) => this.reportPersistenceError(error));
2076
+ });
2077
+ }
2060
2078
  async hydrateReplay() {
2061
2079
  if (!this.replayBuffers || !this.replayPersistence) {
2062
2080
  return;