cross-tab-worker-databus 0.21.24 → 0.21.25

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.
@@ -2586,7 +2586,7 @@ var SDK_VERSION = (
2586
2586
  // declaration's type is `string | undefined` and the export's is `string`
2587
2587
  // (dropping the conditional is TS2322, measured). Recorded here so the leg reads
2588
2588
  // as a shape the harness cannot reach rather than as a case nobody exercised.
2589
- true ? "0.21.24" : ""
2589
+ true ? "0.21.25" : ""
2590
2590
  );
2591
2591
 
2592
2592
  // src/core/data-bus.ts
@@ -3400,15 +3400,21 @@ var CrossTabDataBus = class {
3400
3400
  }
3401
3401
  /** Deliver a message to every local handler registered for its topic,
3402
3402
  * plus every handler registered with a wildcard subscription that matches
3403
- * (e.g. a handler subscribed to "chat.*" receives "chat.room.1"). */
3403
+ * (e.g. a handler subscribed to "chat.*" receives "chat.room.1"). Both sets are
3404
+ * collected before the first handler runs, so a publication is delivered to the
3405
+ * subscribers that existed when its delivery began — see the note in the body. */
3404
3406
  dispatch(message) {
3405
3407
  this.trace.recordDispatched(message.topic);
3406
- this.invokeHandlers(this.topicHandlers.get(message.topic) ?? [], (handler) => handler(message));
3408
+ const exactHandlers = this.topicHandlers.get(message.topic);
3409
+ const delivered = exactHandlers ? Array.from(exactHandlers) : [];
3410
+ const wildcards = [];
3407
3411
  for (const [pattern, handlers] of this.topicHandlers) {
3408
3412
  if (pattern !== message.topic && topicMatchesPattern(pattern, message.topic)) {
3409
- this.invokeHandlers(handlers, (handler) => handler(message));
3413
+ for (const handler of handlers) wildcards.push(handler);
3410
3414
  }
3411
3415
  }
3416
+ this.invokeHandlers(delivered, (handler) => handler(message));
3417
+ this.invokeHandlers(wildcards, (handler) => handler(message));
3412
3418
  this.replayManager.record(message);
3413
3419
  }
3414
3420
  /**