perf(collab): lazy GC timer — start on first peer, stop when empty

The collab overlay was running a 5s setInterval GC timer on every page
load even with zero peers. Now the timer starts only when the first
peer arrives and stops when all peers are garbage collected.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2026-04-09 13:48:18 -04:00
parent 5ddde13b0d
commit 7836b1d956
1 changed files with 3 additions and 0 deletions

View File

@ -136,6 +136,7 @@ export class RStackCollabOverlay extends HTMLElement {
selection: existing?.selection ?? null,
lastSeen: Date.now(),
});
this.#ensureGcTimer();
this.#renderBadge();
if (this.#panelOpen) this.#renderPanel();
}
@ -240,6 +241,7 @@ export class RStackCollabOverlay extends HTMLElement {
module: msg.module || existing?.module,
context: msg.context || existing?.context,
});
this.#ensureGcTimer();
this.#renderBadge();
if (this.#panelOpen) this.#renderPanel();
});
@ -368,6 +370,7 @@ export class RStackCollabOverlay extends HTMLElement {
lastSeen: Date.now(),
};
this.#peers.set(msg.peer, peer);
this.#ensureGcTimer();
this.#renderBadge();
if (!this.#badgeOnly) {
this.#renderCursors();