fix: clear stagger toast timers on unmount in AnnouncementToastProvider

Stagger setTimeout calls inside the for loop were never cleared on
component unmount, causing potential setState calls on unmounted
components when the user navigates away before all toasts fire.

Fixes #1094
This commit is contained in:
mac-agent 2026-04-04 07:02:51 -04:00
parent c2bd2bc935
commit e5a6feb6f6

View file

@ -65,6 +65,8 @@ export function AnnouncementToastProvider() {
if (hasChecked.current) return;
hasChecked.current = true;
const staggerTimers: ReturnType<typeof setTimeout>[] = [];
const timer = setTimeout(() => {
const authed = isAuthenticated();
const active = getActiveAnnouncements(announcements, authed);
@ -74,11 +76,18 @@ export function AnnouncementToastProvider() {
for (let i = 0; i < importantUntoasted.length; i++) {
const announcement = importantUntoasted[i];
setTimeout(() => showAnnouncementToast(announcement), i * 800);
const staggerId = setTimeout(
() => showAnnouncementToast(announcement),
i * 800
);
staggerTimers.push(staggerId);
}
}, 1500);
return () => clearTimeout(timer);
return () => {
clearTimeout(timer);
staggerTimers.forEach((id) => clearTimeout(id));
};
}, []);
return null;