Skip to content

Feat: expose toast.subscribe for subscribing to toast lifecycle outside React - #776

Open
nbarinov wants to merge 2 commits into
emilkowalski:mainfrom
nbarinov:feat/toast-subscribe
Open

Feat: expose toast.subscribe for subscribing to toast lifecycle outside React#776
nbarinov wants to merge 2 commits into
emilkowalski:mainfrom
nbarinov:feat/toast-subscribe

Conversation

@nbarinov

@nbarinov nbarinov commented Aug 4, 2026

Copy link
Copy Markdown

toast already exposes getToasts() / getHistory(), but the only way to react to changes is the React-only useSonner. This exposes the existing internal ToastState.subscribe as toast.subscribe(cb), returning an unsubscribe function – symmetrical to the getters, zero new logic.

Use case: we render a floating checkout pill that must yield to any visible toast ("only one hanging element"). The visibility signal lives in a framework-agnostic store outside the React tree, and today the only way to feed it is a probe component with useSonner mounted next to <Toaster />. With toast.subscribe the store subscribes directly.

Added an e2e test covering add + dismiss events and unsubscribe semantics.

@vercel

vercel Bot commented Aug 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sonner Error Error Aug 4, 2026 8:52am

Request Review

@nbarinov
nbarinov force-pushed the feat/toast-subscribe branch from 94d4b57 to ff3e94a Compare August 11, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant