import.meta.hot.dispose not working?
It seems disposing of side effects does not work. If I have some background task running (job scheduler, db watcher, etc.) in my server, I usually gracefully clean it up on shutdown by listening for signals.
In order for this to work in HMR, my understanding is that I need to register a dispose callback in the file with the side effect. E.g.:
const handle = setInterval(() => {
console.log('ping');
}, 1000);
if (import.meta.hot) {
import.meta.hot.accept();
import.meta.hot.dispose(() => {
console.log('dispose');
clearInterval(handle);
});
}
However, the callback is never called, so I'll have two intervals printing pings.
Reproduction: https://stackblitz.com/edit/node-qfyzmw?file=index.ts,fileWithSideEffect.ts Change e.g. 'ping' -> 'ping1' Reload right side
Are there any news? Looks like a very major blocker
https://github.com/vitejs/vite/issues/7887