cross-tab-worker-databus 0.20.89 → 0.20.91

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.
@@ -849,10 +849,12 @@ var WorkerClusterRuntime = class {
849
849
  const channel = this.channel;
850
850
  this.channel = null;
851
851
  this.handlers.onSuspend?.();
852
- if (typeof globalThis.setTimeout === "function") {
853
- globalThis.setTimeout(() => channel?.close(), 0);
854
- } else {
855
- channel?.close();
852
+ if (channel) {
853
+ if (typeof globalThis.setTimeout === "function") {
854
+ globalThis.setTimeout(() => channel.close(), 0);
855
+ } else {
856
+ channel.close();
857
+ }
856
858
  }
857
859
  }
858
860
  /** Update the worker's connection status and persist the change. */
@@ -2336,7 +2338,7 @@ var DedupManager = class {
2336
2338
  };
2337
2339
 
2338
2340
  // src/core/version.ts
2339
- var SDK_VERSION = true ? "0.20.89" : "";
2341
+ var SDK_VERSION = true ? "0.20.91" : "";
2340
2342
 
2341
2343
  // src/core/data-bus.ts
2342
2344
  var DEFAULT_REPLAY_MAX_PER_TOPIC = 100;
@@ -2518,6 +2520,7 @@ var CrossTabDataBus = class {
2518
2520
  // own broadcastEvent call, which always posts a DataBusMessage.
2519
2521
  onEvent: (eventType, payload, _sourceWorkerId, originTabId) => {
2520
2522
  if (eventType !== PUBLICATION_EVENT) return;
2523
+ if (typeof payload !== "object" || payload === null || typeof payload.topic !== "string") return;
2521
2524
  const incoming = payload;
2522
2525
  const message = incoming.originTabId !== void 0 ? incoming : originTabId !== void 0 ? { ...incoming, originTabId } : incoming;
2523
2526
  if (this.cluster.hasLocalSubscriber(message.topic)) this.dispatch(message);
@@ -3769,7 +3772,7 @@ var WebSocketTransport = class {
3769
3772
  handlers.onStatus(WORKER_STATUS.ERROR);
3770
3773
  handlers.onError(error);
3771
3774
  this.failConnect(error);
3772
- socket.close();
3775
+ this.abortSocket(socket);
3773
3776
  }, timeoutMs);
3774
3777
  }
3775
3778
  socket.onopen = () => {
@@ -3802,6 +3805,7 @@ var WebSocketTransport = class {
3802
3805
  handshakeFailed = true;
3803
3806
  this.failConnect(new Error("WebSocket failed to open."));
3804
3807
  }
3808
+ this.abortSocket(socket);
3805
3809
  };
3806
3810
  socket.onmessage = (event) => {
3807
3811
  if (this.socket === socket && this.handlers === handlers && this.socketActive) {
@@ -3895,6 +3899,14 @@ var WebSocketTransport = class {
3895
3899
  this.connectReject = null;
3896
3900
  reject?.(error);
3897
3901
  }
3902
+ /** Best-effort close for a socket that can no longer carry transport data.
3903
+ * The error that invalidated it has already been reported by the caller. */
3904
+ abortSocket(socket) {
3905
+ try {
3906
+ socket.close();
3907
+ } catch {
3908
+ }
3909
+ }
3898
3910
  clearConnectTimer() {
3899
3911
  if (this.connectTimer !== null) {
3900
3912
  clearTimeout(this.connectTimer);