diff --git a/ui/src/alerts/use-alerts.ts b/ui/src/alerts/use-alerts.ts index a282c589d..df8d17b45 100644 --- a/ui/src/alerts/use-alerts.ts +++ b/ui/src/alerts/use-alerts.ts @@ -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 | 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 };