Toasts, confirms and blocking prompts are functions you call from anywhere and await, rendered by outlets mounted once.

The problem

The confirm dialog wants to live in the component tree, but the decision to ask lives in a mutation handler, a route guard or an error boundary. So you thread open state and callbacks down through props or context to wherever the dialog sits, and the handler turns into a little state machine split across files.

Toasts drift the same way. Each screen writes its own error copy, some forget, and a failure that didn’t toast reads as success.

What I concluded

Make notifications imperative and promise-based. The call site reads as straight-line code:

async function handleDelete(id: string) {
  const ok = await notify.confirm({
    title: "Delete product?",
    description: "This can't be undone.",
    action: "Delete",
  });
  if (!ok) return;
  notify.toast.promise(deleteProduct(id), {
    loading: "Deleting…",
    success: "Deleted.",
  });
}

There are three kinds. A toast is a non-blocking banner, and its promise form shows one toast for the whole life of a request, settling in place to success or error. A confirm resolves true or false. An interrupt has no cancel path at all, for things like an expired session that must be acknowledged.

Behind each dialog is a single-slot store. trigger() returns a promise and stores its resolver, the one outlet in the app root subscribes and renders, and dismissing resolves it. If a second confirm fires while one is pending, the first resolves with its cancel value (false) rather than hanging forever.

Rules

  • One outlet of each kind, in the app root. Two outlets means duplicate dialogs.
  • A replaced call settles. Nobody is left awaiting a dialog that will never show.
  • Error copy has a default. The API layer attaches a user-facing message to errors, and the promise toast uses it, so most call sites never write error copy.
  • Dialogs that need an answer are alert dialogs. Focus moves in (to the safe button on a destructive confirm) and returns to where it was. Interrupts ignore Escape and outside clicks.
  • Toasts are live regions. Polite for normal ones, assertive for errors, and an error that stays open has a keyboard-reachable dismiss.

What you get

Asking the person something is one awaited line, from anywhere. Every notification looks and behaves the same because one component renders all of them.

The demo calls each function from plain buttons. Fire two confirms at once and the first resolves false. Related: Copy button, Modals.