Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import.meta.hot.dispose not working? #53

Open
schummar opened this issue Jul 11, 2022 · 2 comments
Open

import.meta.hot.dispose not working? #53

schummar opened this issue Jul 11, 2022 · 2 comments

Comments

@schummar
Copy link

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

@nick4fake
Copy link

Are there any news? Looks like a very major blocker

@nick4fake
Copy link

vitejs/vite#7887

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants