From a68b7aa080dce1a6918236bb4cb1db44d7c2b69b Mon Sep 17 00:00:00 2001 From: m4air Date: Tue, 15 Sep 2026 16:43:36 -0700 Subject: [PATCH] fix(renderer): dispose activity pagehide listener on HMR --- .../components/activity/activity-clear-completed.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/renderer/src/components/activity/activity-clear-completed.ts b/src/renderer/src/components/activity/activity-clear-completed.ts index 3c6e743a8bb..ead2393612e 100644 --- a/src/renderer/src/components/activity/activity-clear-completed.ts +++ b/src/renderer/src/components/activity/activity-clear-completed.ts @@ -74,10 +74,22 @@ export function flushPendingClearCompletedEvictions(): void { evict() } } +export function disposePendingClearCompletedEvictionListener(): void { + if (typeof window !== 'undefined') { + window.removeEventListener('pagehide', flushPendingClearCompletedEvictions) + } +} + if (typeof window !== 'undefined') { window.addEventListener('pagehide', flushPendingClearCompletedEvictions) } +if (import.meta !== undefined && import.meta.hot) { + // Vite can replace this module without a full renderer reload. Remove the + // pagehide hook so dev sessions do not retain stale eviction closures. + import.meta.hot.dispose(disposePendingClearCompletedEvictionListener) +} + // Why a fallback: sonner only fires onDismiss/onAutoClose for the toast's own close paths; a // `toast.dismiss()` from another caller leaves the eviction pending until pagehide. export const CLEAR_COMPLETED_EVICTION_FALLBACK_MS = 60_000