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.
@@ -2620,7 +2620,7 @@ var SDK_VERSION = (
2620
2620
  // declaration's type is `string | undefined` and the export's is `string`
2621
2621
  // (dropping the conditional is TS2322, measured). Recorded here so the leg reads
2622
2622
  // as a shape the harness cannot reach rather than as a case nobody exercised.
2623
- true ? "0.21.24" : ""
2623
+ true ? "0.21.25" : ""
2624
2624
  );
2625
2625
 
2626
2626
  // src/core/data-bus.ts
@@ -3434,15 +3434,21 @@ var CrossTabDataBus = class {
3434
3434
  }
3435
3435
  /** Deliver a message to every local handler registered for its topic,
3436
3436
  * plus every handler registered with a wildcard subscription that matches
3437
- * (e.g. a handler subscribed to "chat.*" receives "chat.room.1"). */
3437
+ * (e.g. a handler subscribed to "chat.*" receives "chat.room.1"). Both sets are
3438
+ * collected before the first handler runs, so a publication is delivered to the
3439
+ * subscribers that existed when its delivery began — see the note in the body. */
3438
3440
  dispatch(message) {
3439
3441
  this.trace.recordDispatched(message.topic);
3440
- this.invokeHandlers(this.topicHandlers.get(message.topic) ?? [], (handler) => handler(message));
3442
+ const exactHandlers = this.topicHandlers.get(message.topic);
3443
+ const delivered = exactHandlers ? Array.from(exactHandlers) : [];
3444
+ const wildcards = [];
3441
3445
  for (const [pattern, handlers] of this.topicHandlers) {
3442
3446
  if (pattern !== message.topic && topicMatchesPattern(pattern, message.topic)) {
3443
- this.invokeHandlers(handlers, (handler) => handler(message));
3447
+ for (const handler of handlers) wildcards.push(handler);
3444
3448
  }
3445
3449
  }
3450
+ this.invokeHandlers(delivered, (handler) => handler(message));
3451
+ this.invokeHandlers(wildcards, (handler) => handler(message));
3446
3452
  this.replayManager.record(message);
3447
3453
  }
3448
3454
  /**