File tree 3 files changed +17
-0
lines changed
3 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -176,6 +176,8 @@ The following HMR events are dispatched by Vite automatically:
176
176
- ` ' vite:beforePrune' ` when modules that are no longer needed are about to be pruned
177
177
- ` ' vite:invalidate' ` when a module is invalidated with ` import .meta.hot.invalidate()`
178
178
- ` ' vite:error' ` when an error occurs (e.g. syntax error)
179
+ - ` ' vite:ws:disconnect' ` when the WebSocket connection is lost
180
+ - ` ' vite:ws:connect' ` when the WebSocket connection is (re-)established
179
181
180
182
Custom HMR events can also be sent from plugins. See [handleHotUpdate](./api-plugin#handlehotupdate) for more details.
181
183
Original file line number Diff line number Diff line change @@ -81,6 +81,7 @@ function setupWebSocket(
81
81
'open' ,
82
82
( ) => {
83
83
isOpened = true
84
+ notifyListeners ( 'vite:ws:connect' , { webSocket : socket } )
84
85
} ,
85
86
{ once : true } ,
86
87
)
@@ -99,6 +100,8 @@ function setupWebSocket(
99
100
return
100
101
}
101
102
103
+ notifyListeners ( 'vite:ws:disconnect' , { webSocket : socket } )
104
+
102
105
console . log ( `[vite] server connection lost. polling for restart...` )
103
106
await waitForSuccessfulPing ( protocol , hostAndPath )
104
107
location . reload ( )
Original file line number Diff line number Diff line change @@ -12,6 +12,18 @@ export interface CustomEventMap {
12
12
'vite:beforeFullReload' : FullReloadPayload
13
13
'vite:error' : ErrorPayload
14
14
'vite:invalidate' : InvalidatePayload
15
+ 'vite:ws:connect' : WebSocketConnectionPayload
16
+ 'vite:ws:disconnect' : WebSocketConnectionPayload
17
+ }
18
+
19
+ export interface WebSocketConnectionPayload {
20
+ /**
21
+ * @experimental
22
+ * We expose this instance experimentally to see potential usage.
23
+ * This might be removed in the future if we didn't find reasonable use cases.
24
+ * If you find this useful, please open an issue with details so we can discuss and make it stable API.
25
+ */
26
+ webSocket : WebSocket
15
27
}
16
28
17
29
export interface InvalidatePayload {
You can’t perform that action at this time.
0 commit comments