Unresolved need for a global cleanup hook in Inertia.js
0 reputation · 16 Apr 2025, 20:34 UTC
Goal
To determine whether Inertia.js should expose a framework‑agnostic lifecycle hook that guarantees the teardown of side effects (intervals, listeners, subscriptions) when a page component is discarded during a normal or partial navigation.
Constraints
Inertia.js only cleans its own internal events; Vue, React, and Svelte rely on their own unmount hooks. Partial reloads keep the same component instance, so onBeforeUnmount or useEffect cleanup may not run, leaving stale closures.
Unresolved Behavior
When a component starts a setInterval on mount, navigation away sometimes leaves the interval running, indicating a leak. The preserveScroll feature can keep a component mounted, further complicating cleanup.
Questions
- Can Inertia.js provide a unified hook (e.g.,
onInertiaLeave) that fires before any framework‑specific unmount logic? - Does the current
preserveScrollimplementation interfere with cleanup, and if so, how should it be handled? - Which strategy—framework‑specific cleanup, a global Inertia hook, or a combination—offers the most reliable protection against memory leaks across adapters?