cross-tab-worker-databus 0.20.93 → 0.20.95

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.
@@ -45,6 +45,7 @@ function createStorageEventChannel(options) {
45
45
  if (!storage || !win) return null;
46
46
  const key = `${STORAGE_CHANNEL_PREFIX}${name}`;
47
47
  const listeners = /* @__PURE__ */ new Set();
48
+ const senderId = randomId();
48
49
  let sequence = 0;
49
50
  const onStorage = (event) => {
50
51
  if (event.key !== key || event.newValue === null) return;
@@ -57,7 +58,12 @@ function createStorageEventChannel(options) {
57
58
  return;
58
59
  }
59
60
  const event_ = { data: message };
60
- for (const listener of [...listeners]) listener(event_);
61
+ for (const listener of [...listeners]) {
62
+ try {
63
+ listener(event_);
64
+ } catch {
65
+ }
66
+ }
61
67
  };
62
68
  win.addEventListener("storage", onStorage);
63
69
  let closed = false;
@@ -71,7 +77,7 @@ function createStorageEventChannel(options) {
71
77
  postMessage(message) {
72
78
  if (closed) return;
73
79
  sequence += 1;
74
- storage.setItem(key, JSON.stringify({ seq: sequence, message }));
80
+ storage.setItem(key, JSON.stringify({ senderId, seq: sequence, message }));
75
81
  },
76
82
  close() {
77
83
  closed = true;
@@ -525,11 +531,11 @@ var BatchingStorageWriter = class {
525
531
  if (typeof queueMicrotask === "function") queueMicrotask(flush);
526
532
  else setTimeout(flush, 0);
527
533
  }
528
- // Schedule a single retry timer. The guard ensures only one retry is in
529
- // flight at a time; subsequent scheduleRetry calls during the wait are
530
- // no-ops because the first retry will re-flush all pending keys together.
534
+ // Arm the single backoff timer for the pass that just failed. Exactly one
535
+ // retry can be in flight because flush() the only caller — cancels any
536
+ // armed retry on entry and stops at the first failing key, so this always
537
+ // runs with `retryHandle` cleared.
531
538
  scheduleRetry() {
532
- if (this.retryHandle !== null) return;
533
539
  this.retryHandle = setTimeout(() => {
534
540
  this.retryHandle = null;
535
541
  this.flush();
@@ -613,9 +619,8 @@ var WorkerClusterRuntime = class {
613
619
  touchRouteOwnerCache(topicKey, value) {
614
620
  if (this.routeOwnerCache.has(topicKey)) this.routeOwnerCache.delete(topicKey);
615
621
  this.routeOwnerCache.set(topicKey, value);
616
- while (this.routeOwnerCache.size > this.routeOwnerCacheMax) {
617
- const oldest = this.routeOwnerCache.keys().next().value;
618
- if (oldest === void 0) break;
622
+ for (const oldest of this.routeOwnerCache.keys()) {
623
+ if (this.routeOwnerCache.size <= this.routeOwnerCacheMax) break;
619
624
  this.routeOwnerCache.delete(oldest);
620
625
  }
621
626
  }
@@ -2273,9 +2278,8 @@ var DedupManager = class {
2273
2278
  this.accepted += 1;
2274
2279
  this.windowAccepted += 1;
2275
2280
  this.trace.recordDedupAccepted();
2276
- while (this.seenMessageIds.size > this.maxEntries) {
2277
- const oldest = this.seenMessageIds.keys().next().value;
2278
- if (oldest === void 0) break;
2281
+ for (const oldest of this.seenMessageIds.keys()) {
2282
+ if (this.seenMessageIds.size <= this.maxEntries) break;
2279
2283
  this.seenMessageIds.delete(oldest);
2280
2284
  }
2281
2285
  return false;
@@ -2336,7 +2340,7 @@ var DedupManager = class {
2336
2340
  };
2337
2341
 
2338
2342
  // src/core/version.ts
2339
- var SDK_VERSION = true ? "0.20.93" : "";
2343
+ var SDK_VERSION = true ? "0.20.95" : "";
2340
2344
 
2341
2345
  // src/core/data-bus.ts
2342
2346
  var DEFAULT_REPLAY_MAX_PER_TOPIC = 100;
@@ -3528,4 +3532,4 @@ export {
3528
3532
  parseDataBusPublication,
3529
3533
  selectWorkerBackend
3530
3534
  };
3531
- //# sourceMappingURL=chunk-OXEPZGXR.js.map
3535
+ //# sourceMappingURL=chunk-7BPB2Y4E.js.map