AI-native design editor. Open-source Figma alternative.
fix(toast): error toasts auto-dismiss + dedupe + cap stack at 5 (#209)
Chris Gliddon2b4b8c0f63cc
diff --git a/src/components/AppToast.vue b/src/components/AppToast.vueindex e54c920a3..7c0c403db 100644--- a/src/components/AppToast.vue+++ b/src/components/AppToast.vue@@ -16,7 +16,7 @@ const { copy, copied } = useClipboard({ copiedDuring: 1500 })v-for="t in toast.toasts.value":key="t.id"data-test-id="toast-item"- :duration="t.variant === 'error' ? 0 : toast.TOAST_DURATION"+ :duration="t.variant === 'error' ? toast.ERROR_TOAST_DURATION : toast.TOAST_DURATION":class="useToastUI({ tone: t.variant }).base"@update:open="(open) => {@@ -26,7 +26,9 @@ const { copy, copied } = useClipboard({ copiedDuring: 1500 })><icon-lucide-check v-if="t.variant === 'default'" class="mt-0.5 size-3 shrink-0" /><icon-lucide-triangle-alert v-else class="mt-0.5 size-3 shrink-0" />- <ToastDescription class="min-w-0 flex-1 select-text">{{ t.message }}</ToastDescription>+ <ToastDescription class="min-w-0 flex-1 select-text">+ {{ t.message }}<span v-if="t.count > 1" class="ml-1.5 opacity-70">×{{ t.count }}</span>+ </ToastDescription><Tip v-if="t.variant === 'error'" :label="copied ? 'Copied!' : 'Copy error'"><buttondata-test-id="toast-copy-error"diff --git a/src/utils/toast.ts b/src/utils/toast.tsindex 94a3c9cc4..293fa7f65 100644--- a/src/utils/toast.ts+++ b/src/utils/toast.ts@@ -7,24 +7,48 @@ export interface Toast {id: numbermessage: stringvariant: ToastVariant+ /** Number of times this message has been raised since it appeared. */+ count: number}const TOAST_DURATION = 3000+// Errors stay long enough to read but always self-clean, so a+// stuck/repeating error source can't pile up over the canvas.+const ERROR_TOAST_DURATION = 10000+// Hard cap on stacked toasts. Older toasts drop off when a new one would+// exceed this. Belt-and-suspenders against any error source we missed.+const TOAST_STACK_LIMIT = 5const toasts = ref<Toast[]>([])let nextId = 0let errorHandlersInitialized = false+function push(message: string, variant: ToastVariant) {+ // Dedupe: if the same message+variant is already visible, increment+ // its repeat count instead of stacking a duplicate. Prevents the+ // cascade-on-every-frame failure mode where a single unhealthy+ // event source floods the viewport.+ const existing = toasts.value.find((t) => t.message === message && t.variant === variant)+ if (existing) {+ existing.count += 1+ return+ }+ toasts.value.push({ id: ++nextId, message, variant, count: 1 })+ if (toasts.value.length > TOAST_STACK_LIMIT) {+ toasts.value.splice(0, toasts.value.length - TOAST_STACK_LIMIT)+ }+}+function info(message: string) {- toasts.value.push({ id: ++nextId, message, variant: 'default' })+ push(message, 'default')}function warning(message: string) {- toasts.value.push({ id: ++nextId, message, variant: 'warning' })+ push(message, 'warning')}function error(message: string) {- toasts.value.push({ id: ++nextId, message, variant: 'error' })+ push(message, 'error')}function remove(id: number) {@@ -51,5 +75,6 @@ export const toast = {remove,toasts,setupGlobalErrorHandler,- TOAST_DURATION+ TOAST_DURATION,+ ERROR_TOAST_DURATION}