fix(ui): read alerts once per event burst, not once per replayed event
This commit is contained in:
1 file changed
+10
-2
@@ -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 };
|
||||
|
||||
Reference in new issue
Block a user