@@ -8,6 +8,7 @@ import { getErrorMessage } from '../utils/getErrorMessage.js';
88
99const MAX_TOAST_DESCRIPTION_CHARS = 480 ;
1010const MAX_VISIBLE_TOASTS = 5 ;
11+ const ERROR_TOAST_TTL_MS = 10_000 ;
1112const SUCCESS_TOAST_TTL_MS = 3000 ;
1213const SDK_TIMEOUT_TOAST_TITLE = 'Request timed out' ;
1314const SDK_TIMEOUT_TOAST_DESCRIPTION = 'The request took too long and was cancelled. Try again.' ;
@@ -67,19 +68,24 @@ export function ToasterProvider({ children }: { children: ReactNode }) {
6768 setToasts ( prev => prev . filter ( t => t . id !== id ) ) ;
6869 } , [ ] ) ;
6970
70- const showError = useCallback ( ( error : unknown ) => {
71- console . error ( '[trueforge-ui]' , error ) ;
72- const item : ToastItem = { id : nextToastId ( ) , variant : 'error' , ...normalizeError ( error ) } ;
73- setToasts ( prev => [ ...prev , item ] . slice ( - MAX_VISIBLE_TOASTS ) ) ;
74- } , [ ] ) ;
71+ const showError = useCallback (
72+ ( error : unknown ) => {
73+ console . error ( '[trueforge-ui]' , error ) ;
74+ const id = nextToastId ( ) ;
75+ const item : ToastItem = { id, variant : 'error' , ...normalizeError ( error ) } ;
76+ setToasts ( prev => [ ...prev , item ] . slice ( - MAX_VISIBLE_TOASTS ) ) ;
77+ if ( typeof window !== 'undefined' ) {
78+ window . setTimeout ( ( ) => dismiss ( id ) , ERROR_TOAST_TTL_MS ) ;
79+ }
80+ } ,
81+ [ dismiss ] ,
82+ ) ;
7583
7684 const showSuccess = useCallback (
7785 ( content : ToastContent ) => {
7886 const id = nextToastId ( ) ;
7987 const item : ToastItem = { id, variant : 'success' , ...content } ;
8088 setToasts ( prev => [ ...prev , item ] . slice ( - MAX_VISIBLE_TOASTS ) ) ;
81- // Success is a transient confirmation — auto-dismiss so it doesn't linger. Errors persist
82- // (a dev may need to read or copy them).
8389 if ( typeof window !== 'undefined' ) {
8490 window . setTimeout ( ( ) => dismiss ( id ) , SUCCESS_TOAST_TTL_MS ) ;
8591 }
0 commit comments