Skip to content

feat(toast): queue toasts behind a limit, in priority order, and pause them away from the front - #2517

Open
im-apratap wants to merge 1 commit into
nsgo-dev:mainfrom
im-apratap:feat/toast-queue
Open

im-apratap wants to merge 1 commit into
nsgo-dev:mainfrom
im-apratap:feat/toast-queue

Conversation

@im-apratap

Copy link
Copy Markdown

Part of #2507. This is the queue and the status region; the keyboard-focus pause and the Escape scoping are noted at the end.

What changes

  • A FIFO queue with a waiting count. base/toast.Manager takes a Limit and presents the highest priorities first, then the oldest, rather than the newest and dropping the oldest from view. Visible() returns what shows and Waiting() how many are behind it. A waiting toast keeps its place and does not move at all: its entering motion and its timeout start when it shows, so a toast the reader never saw no longer expires unseen.
  • Duplicates merge in place. Push of an existing id updates that toast where it is, keeping its position and its status, instead of moving it to the newest slot; one that is leaving shows again.
  • Priority. Priority with PriorityNormal and PriorityHigh and Manager.PushPriority order the queue, so an error or a running job's progress stays in front of the toasts waiting. ui.Toaster gives ToastError and a toast with a negative Duration high priority without asking, and ToastContent.Priority says otherwise.
  • The app away from the front. ui.Toaster passes cx.Env().Lifecycle() != core.LifecycleActive through Advance, so a window in the background holds the countdown instead of running toasts out unseen. Toaster.Waiting() is a signal's value, so a stack's own +N follows the queue.
  • A polite status region. toast.Toast.Polite reads it as core.RoleStatus, which is a polite live region, rather than core.RoleAlert; ui.Toasts.Polite applies it to every toast but errors.
  • Configurable motion. ui.Toasts.Motion sets the entering and leaving durations (Sonner's where a field is zero), and ReduceMotion leaves none.
  • tsx/toasts.go follows: visible(limit) sets the manager's limit, and entries expose their priority.

Verification

  • go tool nsgo check -target linux — vetted for linux_arm64 and linux_x64.
  • go tool nsgo test ./base/toast — 4 passed, including TestToastLimitQueuesAndPushMergesInPlace (queue order, in-place merge, priority, the leaving toast making room) and TestToastWaitingKeepsItsTimeoutUntilItShows (a waiting toast's timeout begins when it shows).
  • go tool nsgo test ./ui — 269 passed, including TestToastsQueue (limit 1 shows the oldest, an error takes the slot, a polite toast reads RoleStatus and an error RoleAlert, and a background window holds the countdown).
  • go tool nsgo test ./tsx — 311 passed.
  • go tool nsgo test -run Toast ./examples/gallery — 2 passed.
  • go run ./tools/changelog check — valid.

Still open in #2507

  • Pausing on keyboard focus inside the toast region. core sets its FocusWithin state internally and exposes no query or signal for a view to read it, so this needs a core API first. I did not invent one here.
  • Scoping Escape to a focused toast, with focus restoration. The stack still hears Escape whenever it holds toasts (OnCancel), as before; scoping it depends on the same focus information.

I can follow up on both once the focus API is settled, or add whichever of them you want in this PR.

🤖 Generated with Codebuff

…e them away from the front

`base/toast.Manager.Visible(limit)` dropped the oldest toast and kept the
newest, and `Advance` counted every toast's timeout down while it was
hidden, so a toast the user never saw expired. A repeated id moved its
toast to the newest slot, and nothing kept an error or a running job's
progress in front.

The Manager takes a Limit and presents the highest priority first, then
the oldest, the rest waiting in their place with their motion and
timeout not started; Waiting counts them. Push merges a repeated id into
its toast's place, and PushPriority puts an error or progress ahead of
the toasts waiting. ui.Toaster pauses the timeouts while the app is not
in front, counts what waits, and shows errors and toasts that stay until
dismissed first. ui.Toasts reads its toasts as a polite status region
with Polite and takes entering and leaving from Motion, none under
ReduceMotion.

Part of nsgo-dev#2507.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@github-actions github-actions Bot added size/M enhancement New feature or request documentation Improvements or additions to documentation base ui tsx labels Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

base documentation Improvements or additions to documentation enhancement New feature or request size/M tsx ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant