cross-tab-worker-databus 0.21.14 → 0.21.16

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.
@@ -2505,7 +2505,7 @@ var DedupManager = class {
2505
2505
  };
2506
2506
 
2507
2507
  // src/core/version.ts
2508
- var SDK_VERSION = true ? "0.21.14" : "";
2508
+ var SDK_VERSION = true ? "0.21.16" : "";
2509
2509
 
2510
2510
  // src/core/data-bus.ts
2511
2511
  var DEFAULT_REPLAY_MAX_PER_TOPIC = 100;
@@ -3456,12 +3456,18 @@ var CrossTabDataBus = class {
3456
3456
  subscribeTransport(topic) {
3457
3457
  if (this.transportSubscribedTopics.has(topic)) return false;
3458
3458
  this.transportSubscribedTopics.add(topic);
3459
- this.runTransport(() => this.transport.subscribe(topic));
3459
+ this.runTransport(
3460
+ () => this.transport.subscribe(topic),
3461
+ () => this.transportSubscribedTopics.has(topic)
3462
+ );
3460
3463
  return true;
3461
3464
  }
3462
3465
  unsubscribeTransport(topic) {
3463
3466
  if (!this.transportSubscribedTopics.delete(topic)) return false;
3464
- this.runTransport(() => this.transport.unsubscribe(topic));
3467
+ this.runTransport(
3468
+ () => this.transport.unsubscribe(topic),
3469
+ () => !this.transportSubscribedTopics.has(topic)
3470
+ );
3465
3471
  return true;
3466
3472
  }
3467
3473
  /** Invoke `callback` for each item in `handlers`, isolating a throwing
@@ -3579,8 +3585,15 @@ var CrossTabDataBus = class {
3579
3585
  * Run a transport operation now if the transport is ready, otherwise queue
3580
3586
  * it behind the start promise. This ensures subscribe/unsubscribe calls made
3581
3587
  * during startup are not lost.
3588
+ *
3589
+ * `stillWanted` expresses the deferred work as the *current* desired state
3590
+ * rather than a captured call, and is checked at each place that resumes on a
3591
+ * later task — the recovery gate and the opening flush. The immediate branch
3592
+ * carries no check because every path into it evaluates the desired state in
3593
+ * the same task: a caller that just mutated `transportSubscribedTopics`, or
3594
+ * the gate re-entry one line above.
3582
3595
  */
3583
- runTransport(operation) {
3596
+ runTransport(operation, stillWanted) {
3584
3597
  if (this.suspended) return;
3585
3598
  if (this.recoveryGate && !this.stopping) {
3586
3599
  const gate = this.recoveryGate;
@@ -3590,7 +3603,8 @@ var CrossTabDataBus = class {
3590
3603
  void gate.then(() => {
3591
3604
  this.recoveryWaiters -= 1;
3592
3605
  if (this.stopping || this.suspended || cancellationToken !== this.recoveryCancellationToken) return;
3593
- this.runTransport(operation);
3606
+ if (stillWanted && !stillWanted()) return;
3607
+ this.runTransport(operation, stillWanted);
3594
3608
  });
3595
3609
  return;
3596
3610
  }
@@ -3611,6 +3625,7 @@ var CrossTabDataBus = class {
3611
3625
  void ready.then(
3612
3626
  () => {
3613
3627
  if (!this.started || this.stopping || this.suspended) return;
3628
+ if (stillWanted && !stillWanted()) return;
3614
3629
  return operation();
3615
3630
  },
3616
3631
  // The opening promise reports its own lifecycle failure through