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.
|
// may land, or an older list overwrites a newer one.
|
||||||
let latest = 0;
|
let latest = 0;
|
||||||
let wired = false;
|
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() {
|
async function load() {
|
||||||
const seq = ++latest;
|
const seq = ++latest;
|
||||||
@@ -66,8 +74,8 @@ export function useAlerts() {
|
|||||||
if (!wired) {
|
if (!wired) {
|
||||||
wired = true;
|
wired = true;
|
||||||
const { activity, connectionRevision } = storeToRefs(useSessionStore());
|
const { activity, connectionRevision } = storeToRefs(useSessionStore());
|
||||||
watch(() => activity.value.find((event) => event.kind === "alert")?.id, load);
|
watch(() => activity.value.find((event) => event.kind === "alert")?.id, scheduleLoad);
|
||||||
watch(connectionRevision, load);
|
watch(connectionRevision, scheduleLoad);
|
||||||
onMounted(load);
|
onMounted(load);
|
||||||
}
|
}
|
||||||
return { alerts, failed, loaded, dismissError, dismiss, dismissAll };
|
return { alerts, failed, loaded, dismissError, dismiss, dismissAll };
|
||||||
|
|||||||
Reference in new issue
Block a user