fix(renderer): dispose activity pagehide listener on HMR

This commit is contained in:
m4air
2026-09-15 16:43:36 -07:00
parent 202c1d72a9
commit a68b7aa080
@@ -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