You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Toast is never shown if called before Toaster subscribes to ToastState #723
Toaster component calls ToastState.subscribe in a useEffect (code). If the app calls toast(...) on page load, it might run before the call to subscribe and the toast is never shown.
Example code from our app:
constToastShownOnPageLoad=()=>{useEffect(()=>{if(!shouldShowToast)// This toast will never show upconsttoastId=toast.custom(...);return()=>{toast.dismiss(toastId);};},[shouldShowToast]);returnnull;}constApp=()=>{return<div><ToastShownOnPageLoad/><Toaster/></div>}
A possible workaround is to wrap the call to toast.custom(...) in a setTimeout with 0 delay like so:
constToastShownOnPageLoad=()=>{useEffect(()=>{if(!shouldShowToast)lettoastId;setTimeout(()=>{// This toast will show uptoastId=toast.custom(...);});return()=>{if(toastId)toast.dismiss(toastId);};},[shouldShowToast]);returnnull;}constApp=()=>{return<div><ToastShownOnPageLoad/><Toaster/></div>}
or alternatively to re-arrange the render order of your components so that Toaster is rendered before ToastShownOnPageLoad (useEffect hooks seem to run in the order the components were rendered, but I haven't confirmed that this is guaranteed):
Yeah, I've run into this issue as well. Would be cool if sonner internally would queue up toast calls until Toaster has mounted and and then flush the queue after Toaster has mounted.
Activity
DanielGiljam commentedon Dec 19, 2025
Yeah, I've run into this issue as well. Would be cool if
sonnerinternally would queue uptoastcalls untilToasterhas mounted and and then flush the queue afterToasterhas mounted.Fix a batch of reported issues
Fix a batch of reported issues (#777)