fix(ui): read alerts once per event burst, not once per replayed event
deploy / plan (push) Failing after 1s
deploy / gate (push) Skipped
deploy / archied-image (push) Skipped
deploy / agent-image (push) Skipped
deploy / dist-zip (push) Skipped

This commit is contained in:
sam committed 2026-11-08 23:21:06 +11:00
1 parent 074ebbd931
commit 67fa57008e
1 file changed
+10 -2
+10 -2
View File
@@ -21,6 +21,14 @@ const dismissError = ref("");
// may land, or an older list overwrites a newer one.
let latest = 0;
let wired = false;
// A reconnect replays the backlog, one alert event at a time; read the list
// once per burst instead of once per event.
let pending: ReturnType<typeof setTimeout> | undefined;
function scheduleLoad() {
clearTimeout(pending);
pending = setTimeout(load, 500);
}
async function load() {
const seq = ++latest;
@@ -66,8 +74,8 @@ export function useAlerts() {
if (!wired) {
wired = true;
const { activity, connectionRevision } = storeToRefs(useSessionStore());
watch(() => activity.value.find((event) => event.kind === "alert")?.id, load);
watch(connectionRevision, load);
watch(() => activity.value.find((event) => event.kind === "alert")?.id, scheduleLoad);
watch(connectionRevision, scheduleLoad);
onMounted(load);
}
return { alerts, failed, loaded, dismissError, dismiss, dismissAll };