diff --git a/src/lib/stores/toasts.svelte.ts b/src/lib/stores/toasts.svelte.ts index 0d91b85..7f1ff88 100644 --- a/src/lib/stores/toasts.svelte.ts +++ b/src/lib/stores/toasts.svelte.ts @@ -18,6 +18,12 @@ import { errorMessage } from "$lib/utils/errors.js"; let nextId = 1; +// Soft cap on how many toasts can be queued at once. Error toasts are sticky +// (duration: 0) so a misbehaving command that fires errors in a loop can pile +// up indefinitely without this cap. When exceeded, the oldest toast is +// evicted to make room. +const MAX_TOASTS = 50; + function defaultDuration(severity: ToastSeverity): number { switch (severity) { case "success": return 3000; @@ -38,6 +44,9 @@ function createToastsStore() { const duration = defaultDuration(severity); const toast = { id, severity, title, body: body ?? '', duration }; items.push(toast); + if (items.length > MAX_TOASTS) { + items.splice(0, items.length - MAX_TOASTS); + } if (duration > 0) { setTimeout(() => dismiss(id), duration); }