@mmstack/primitives 22.10.1 → 22.10.2

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.
@@ -6917,14 +6917,27 @@ function storeTabSync(sig, opt, bus, injector) {
6917
6917
  case 'hello': {
6918
6918
  if (phase !== 'live' || msg.from === sync.origin)
6919
6919
  return;
6920
- // first responder wins: jittered answer, cancelled when someone else answers first
6921
- const timer = setTimeout(() => {
6922
- responseTimers.delete(msg.from);
6920
+ const respond = () => {
6923
6921
  const snap = sync.snapshot();
6924
6922
  const covered = Object.entries(snap.wm).every(([origin, v]) => (msg.wm[origin] ?? 0) >= v);
6925
6923
  post(covered
6926
6924
  ? { t: 'uptodate', proto: OP_PROTO_VERSION, to: msg.from }
6927
6925
  : { t: 'state', proto: OP_PROTO_VERSION, to: msg.from, state: snap });
6926
+ };
6927
+ // `jitterMs: 0` answers HERE, in the message handler, with no timer at all. This is the
6928
+ // difference between "as fast as possible" and "possible": a hidden tab's timers are
6929
+ // aligned to ≥1s, so even setTimeout(0) from a backgrounded responder routinely outlives
6930
+ // the joiner's hello window — while message events are not throttled. A channel whose
6931
+ // typical population is one hidden responder (a builder answering its preview tab) opts
6932
+ // in; the jittered path stays the default for many-peer channels.
6933
+ if (jitterMs === 0) {
6934
+ respond();
6935
+ return;
6936
+ }
6937
+ // first responder wins: jittered answer, cancelled when someone else answers first
6938
+ const timer = setTimeout(() => {
6939
+ responseTimers.delete(msg.from);
6940
+ respond();
6928
6941
  }, Math.random() * jitterMs);
6929
6942
  responseTimers.set(msg.from, timer);
6930
6943
  return;