Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat[toasts]: instead of queueing, remove oldest toasts (#2899)
Peter Chinman62f857bd702e
diff --git a/js/app/packages/core/component/Toast/Toast.tsx b/js/app/packages/core/component/Toast/Toast.tsxindex 98bc0c74cf..f8385669e4 100644--- a/js/app/packages/core/component/Toast/Toast.tsx+++ b/js/app/packages/core/component/Toast/Toast.tsx@@ -3,22 +3,22 @@ import ExclamationIcon from '@icon/regular/exclamation-mark.svg';import Spinner from '@icon/regular/spinner.svg';import XIcon from '@icon/regular/x.svg';import { Toast, toaster } from '@kobalte/core/toast';+import { Panel } from '@ui';+import { Button } from '@ui/components/Button';+import { cn } from '@ui/utils/classname';import type { Component, JSX } from 'solid-js';import {- Show,+ createEffect,+ createSignal,For,- Switch,Match,- createSignal,- onMount,- onCleanup,- createEffect,on,+ onCleanup,+ onMount,+ Show,+ Switch,} from 'solid-js';import { Dynamic } from 'solid-js/web';-import { Panel } from '@ui';-import { Button } from '@ui/components/Button';-import { cn } from '@ui/utils/classname';export enum ToastType {SUCCESS = 'success',@@ -142,6 +142,14 @@ interface ToastMessage {const recentToasts: Map<string, ToastMessage> = new Map();const THROTTLE_DURATION = 3000;+/** Maximum number of toasts visible at one time in the main region. */+const MAX_VISIBLE_TOASTS = 3;+/**+ * Ordered list of active (non-persistent) toast IDs in the main region,+ * oldest first. Used to evict the oldest toast when the limit is exceeded.+ */+const activeToastIds: number[] = [];+function createToastKey(message: string, type: ToastType): string {return `${type}:${message}`;}@@ -226,6 +234,8 @@ function ToastContent(props: {duration?: number;embed?: Component;custom?: CustomToastConfig;+ /** Called when this toast is removed from the DOM, so callers can clean up tracking. */+ onDismiss?: () => void;}) {const styles = () => (props.toastType ? TOAST_STYLES[props.toastType] : null);@@ -244,6 +254,8 @@ function ToastContent(props: {let elapsed = 0;+ onCleanup(() => props.onDismiss?.());+onMount(() => {// Persistent toasts never auto-dismissif (props.persistent) return;@@ -483,6 +495,13 @@ function createToast(}}+ // Evict the oldest visible toast when the display limit is reached, so the+ // newest toast always appears immediately instead of being queued.+ if (activeToastIds.length >= MAX_VISIBLE_TOASTS) {+ const oldestId = activeToastIds.shift();+ if (oldestId !== undefined) toaster.dismiss(oldestId);+ }+const toastId = toaster.show((props) => (<ToastContent@@ -494,11 +513,17 @@ function createToast(// Pass duration only when explicitly provided — this is what gates the progress bar.// When undefined, ToastContent falls back to its own default dismiss timing internally.duration={duration}+ onDismiss={() => {+ const idx = activeToastIds.indexOf(props.toastId);+ if (idx !== -1) activeToastIds.splice(idx, 1);+ }}/>),{ region: 'toast-region' });+ activeToastIds.push(toastId);+if (!stack) {const key = createToastKey(message, toastType);const timeoutId = setTimeout(() => {