feat(client): add WebSocket connections events#13334
Conversation
|
|
packages/vite/types/customEvent.d.ts
Outdated
| 'vite:ws:connect': WebSocket | ||
| 'vite:ws:disconnect': WebSocket |
There was a problem hiding this comment.
Do you need the WebSocket instance? It concerns me a bit that WebSocket instance has a broad interface. (e.g. socket.send())
There was a problem hiding this comment.
It isn't required for the original request. @antfu maybe we should add this param once we have a real use case? And once we go there, it could be a Payload object like the others so we could extend it in the future if needed.
There was a problem hiding this comment.
I don't have a strong opinion either on having it or not. I was just thinking why not, since we have that information.
A few notes added to the consideration:
WebSocketit's a web standard so I don't need to worry about the API been changed- If we say web socket is an implementation detail,
vite:wsalready indicates it's web socket. Later if we really find an alternative way of making the connection, those hooks won't be called so there will be no conflicts like the generalvite:connect - On the node side, plugins already have logics with WebSocket. It's not really an implementation detail we can't reveal.
I don't expect this will be changed and won't add much maintenance interface to us.
I do see one downside is that ppl might start using it and mess it around to break Vite - and then send requests to support very niche usages. But that could happen everywhere and we need to prevent that for sure.
There was a problem hiding this comment.
Good points, I think we can talk about this in the next team meeting 👍🏼
I assume you also don't think it is a good idea to have a Payload object here.
|
We started a discussion to gather feedback so we can stabilize |
Description
Currently, when Vite's WS connection close/reconnects, it only prints to the console, but no way for other integrations to know it programmatically.
This PR introduced two client events,
vite:ws:connectandvite:ws:disconnect. This would allow plugins and meta frameworks to display better connection indicators within UI, improving the DX by some extent.Additional context
Motivation on my side is: nuxt/devtools#243
What is the purpose of this pull request?