@mmstack/primitives 21.10.1 → 21.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.
|
@@ -6874,14 +6874,27 @@ function storeTabSync(sig, opt, bus, injector) {
|
|
|
6874
6874
|
case 'hello': {
|
|
6875
6875
|
if (phase !== 'live' || msg.from === sync.origin)
|
|
6876
6876
|
return;
|
|
6877
|
-
|
|
6878
|
-
const timer = setTimeout(() => {
|
|
6879
|
-
responseTimers.delete(msg.from);
|
|
6877
|
+
const respond = () => {
|
|
6880
6878
|
const snap = sync.snapshot();
|
|
6881
6879
|
const covered = Object.entries(snap.wm).every(([origin, v]) => (msg.wm[origin] ?? 0) >= v);
|
|
6882
6880
|
post(covered
|
|
6883
6881
|
? { t: 'uptodate', proto: OP_PROTO_VERSION, to: msg.from }
|
|
6884
6882
|
: { t: 'state', proto: OP_PROTO_VERSION, to: msg.from, state: snap });
|
|
6883
|
+
};
|
|
6884
|
+
// `jitterMs: 0` answers HERE, in the message handler, with no timer at all. This is the
|
|
6885
|
+
// difference between "as fast as possible" and "possible": a hidden tab's timers are
|
|
6886
|
+
// aligned to ≥1s, so even setTimeout(0) from a backgrounded responder routinely outlives
|
|
6887
|
+
// the joiner's hello window — while message events are not throttled. A channel whose
|
|
6888
|
+
// typical population is one hidden responder (a builder answering its preview tab) opts
|
|
6889
|
+
// in; the jittered path stays the default for many-peer channels.
|
|
6890
|
+
if (jitterMs === 0) {
|
|
6891
|
+
respond();
|
|
6892
|
+
return;
|
|
6893
|
+
}
|
|
6894
|
+
// first responder wins: jittered answer, cancelled when someone else answers first
|
|
6895
|
+
const timer = setTimeout(() => {
|
|
6896
|
+
responseTimers.delete(msg.from);
|
|
6897
|
+
respond();
|
|
6885
6898
|
}, Math.random() * jitterMs);
|
|
6886
6899
|
responseTimers.set(msg.from, timer);
|
|
6887
6900
|
return;
|