Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/perfect-turtles-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@heroui/toast": patch
---

Fix toast items closing in reverse order. Toasts now close in proper FIFO instead of LIFO (#5096)
7 changes: 4 additions & 3 deletions packages/components/toast/src/use-toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export function useToast<T extends ToastProps>(originalProps: UseToastProps<T>)
}, []);

const [isLoading, setIsLoading] = useState<boolean>(!!promiseProp);
const [isToastExiting, setIsToastExiting] = useState(false);

useEffect(() => {
if (!promiseProp) return;
Expand All @@ -220,7 +221,7 @@ export function useToast<T extends ToastProps>(originalProps: UseToastProps<T>)
startTime.current = timestamp;
}

if (isToastHovered || isRegionExpanded || index != total - 1) {
if (isToastHovered || isRegionExpanded) {
pausedTime.current += timestamp - startTime.current;
startTime.current = null;
animationRef.current = requestAnimationFrame(updateProgress);
Expand All @@ -232,7 +233,7 @@ export function useToast<T extends ToastProps>(originalProps: UseToastProps<T>)

timeElapsed.current = elapsed;
if (timeElapsed.current >= timeout) {
state.close(toast.key);
setIsToastExiting(true);
}

progressRef.current = Math.min((elapsed / timeout) * 100, 100);
Expand Down Expand Up @@ -264,6 +265,7 @@ export function useToast<T extends ToastProps>(originalProps: UseToastProps<T>)
total,
isRegionExpanded,
isLoading,
setIsToastExiting,
]);

const Component = as || "div";
Expand All @@ -283,7 +285,6 @@ export function useToast<T extends ToastProps>(originalProps: UseToastProps<T>)
}, []);

const [initialHeight, setInitialHeight] = useState<number>(0);
const [isToastExiting, setIsToastExiting] = useState(false);

// Following was inspired from sonner ❀️
useLayoutEffect(() => {
Expand Down