[Bug]: Toast priority promotes lower values first, but the docs say higher priority toasts render first
Component
Toast
Package version
9.74.10
React version
19.3.1
Environment
System:
OS: Windows 11 10.0.26300
CPU: (24) x64 AMD Ryzen 9 7900X 12-Core Processor
Browsers:
Chrome: 155.0.8059.85
npmPackages:
@fluentui/react-components: 9.74.10 => 9.74.10
@fluentui/react-toast: 9.8.5 => 9.8.5
react: 19.3.1 => 19.3.1
react-dom: 19.3.1 => 19.3.1
Current Behavior
ToastOptions.priority is documented as "Higher priority toasts will be rendered before lower priority toasts", but the queue promotes the lowest value first.
The documentation, in packages/react-components/react-toast/library/src/state/types.ts:
/**
* Higher priority toasts will be rendered before lower priority toasts
*/
priority: number;
The implementation, in createToaster.ts, builds a min heap with:
return a.priority - b.priority;
A min heap with that comparator dequeues the smallest value first, so among queued toasts the lowest priority is promoted to visible first.
The existing test in createToaster.test.ts asserts the lower-first behavior, so this is covered by tests rather than accidental. With limit: 1 and queued priorities 1, 2 and 4, the toast with priority 1 becomes visible first, then 2, then 4.
So the documentation and the implementation describe opposite orderings, and only one of them can be right.
Expected Behavior
Either the documentation or the comparator needs to change, and they should agree.
If the intent is that a higher number means more urgent, then the comparator should be b.priority - a.priority. If the intent is that a lower number means more urgent, the documentation should say so.
Changing the behavior would affect any app that already relies on the current order, so updating the documentation may be the safer choice. I am happy to send a PR for whichever the Toast owners prefer.
Reproduction
Runnable: https://stackblitz.com/github/jakesalvesen/fluentui-37136-repro
That project mounts a Toaster with limit={1}, dispatches a toast at priority: 1 and another at priority: 10, dismisses the visible toast, and reports which queued toast is promoted. It reproduces on @fluentui/react-toast 9.8.5, where the toast at priority: 1 is promoted.
The relevant source is here:
https://github.com/microsoft/fluentui/blob/master/packages/react-components/react-toast/library/src/state/vanilla/createToaster.ts#L54-L66
Steps to reproduce
- Render a
Toasterwithlimit={1}. - Dispatch toast A with the default priority. It becomes visible.
- Dispatch toast B with
priority: 1. - Dispatch toast C with
priority: 10. - Dismiss A.
- Observe that B becomes visible, not C.
The same behavior is asserted in the existing test should dequeue toasts in priority in createToaster.test.ts, which queues priorities 1, 2 and 4 and expects them to become visible in that order.
Are you reporting an Accessibility issue?
no
Suggested severity
Medium - Has workaround
Invert the priority values (use lower numbers for more urgent toasts).
Products/sites affected
Apps that queue more toasts than their Toaster limit and rely on priority to control which appears first.
Are you willing to submit a PR to fix?
yes
Validations
- [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [x] The provided reproduction is a minimal reproducible example of the bug.
Thanks for highlighting the ambiguity. The current comparator and existing tests consistently promote lower numeric values first. “Higher priority” does not currently define whether urgency corresponds to a larger or smaller number. Clarifying the documentation to say that lower numeric values are served first would preserve existing behavior; reversing the comparator would change ordering for existing consumers. The Toast owners should confirm the intended contract before changing that behavior.
Thanks, @paolo-aliprandi. Agreed: clarifying the documentation is the safer route, since reversing the comparator would change the order for existing consumers.
#37160 by @vishalrajofficial now does that. It states that lower numeric values are served first, documents the default of 0 (which matches the default options in createToaster.ts), and leaves the comparator alone. I will not open a duplicate. If the Toast owners confirm lower-first as the contract, #37160 can close this issue.
Thanks for the detailed write-up. The current comparator and tests treat lower numeric values as served first, and #37160 documents that without changing behavior. Toast owners, please confirm lower-first is the intended contract; if so, #37160 can close this.