-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[HMR API] add the ability to remove listeners added using import.meta.hot.on()
#14185
Comments
I think this is a nice idea. Can you further explain your usecase for this feature? |
It's mostly for advanced use case with vite, where you create a plugin to communicate with the websocket Because those events can basically be used to request something from vite, you'll send an event with send and wait for the answer with |
Alright 👍 So sounds like the main use-case is to listen to something once. I guess you could used a temporary variable to block it so the listener only runs once. FYI vite/packages/vite/src/client/client.ts Lines 521 to 533 in c58fc41
|
Description
While the ability to add events to communicate with the vite websocket is great, it would be even greater if we could also remove the events we added using
import.meta.hot.on('event', () => {})
Suggested solution
Add an
off
and maybe aonce
method, or return a callback fromon
that can be called to remove the listenerAlternative
There is no alternative, right now once an event is added it can never be removed
Code reference
vite/packages/vite/src/client/client.ts
Lines 598 to 606 in 220a413
Validations
The text was updated successfully, but these errors were encountered: