mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-08 23:32:40 +02:00
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:
parent
c2bd2bc935
commit
e5a6feb6f6
1 changed files with 11 additions and 2 deletions
|
|
@ -65,6 +65,8 @@ export function AnnouncementToastProvider() {
|
||||||
if (hasChecked.current) return;
|
if (hasChecked.current) return;
|
||||||
hasChecked.current = true;
|
hasChecked.current = true;
|
||||||
|
|
||||||
|
const staggerTimers: ReturnType<typeof setTimeout>[] = [];
|
||||||
|
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
const authed = isAuthenticated();
|
const authed = isAuthenticated();
|
||||||
const active = getActiveAnnouncements(announcements, authed);
|
const active = getActiveAnnouncements(announcements, authed);
|
||||||
|
|
@ -74,11 +76,18 @@ export function AnnouncementToastProvider() {
|
||||||
|
|
||||||
for (let i = 0; i < importantUntoasted.length; i++) {
|
for (let i = 0; i < importantUntoasted.length; i++) {
|
||||||
const announcement = importantUntoasted[i];
|
const announcement = importantUntoasted[i];
|
||||||
setTimeout(() => showAnnouncementToast(announcement), i * 800);
|
const staggerId = setTimeout(
|
||||||
|
() => showAnnouncementToast(announcement),
|
||||||
|
i * 800
|
||||||
|
);
|
||||||
|
staggerTimers.push(staggerId);
|
||||||
}
|
}
|
||||||
}, 1500);
|
}, 1500);
|
||||||
|
|
||||||
return () => clearTimeout(timer);
|
return () => {
|
||||||
|
clearTimeout(timer);
|
||||||
|
staggerTimers.forEach((id) => clearTimeout(id));
|
||||||
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue