@@ -9,7 +9,11 @@ import colors from 'picocolors'
9
9
import type { WebSocket as WebSocketRaw } from 'ws'
10
10
import { WebSocketServer as WebSocketServerRaw_ } from 'ws'
11
11
import type { WebSocket as WebSocketTypes } from 'dep-types/ws'
12
- import type { ErrorPayload , HotPayload } from 'types/hmrPayload'
12
+ import type {
13
+ ErrorPayload ,
14
+ FullReloadPayload ,
15
+ HotPayload ,
16
+ } from 'types/hmrPayload'
13
17
import type { InferCustomEventPayload } from 'types/customEvent'
14
18
import type { ResolvedConfig } from '..'
15
19
import { isObject } from '../utils'
@@ -231,9 +235,9 @@ export function createWebSocketServer(
231
235
} )
232
236
} )
233
237
socket . send ( JSON . stringify ( { type : 'connected' } ) )
234
- if ( bufferedError ) {
235
- socket . send ( JSON . stringify ( bufferedError ) )
236
- bufferedError = null
238
+ if ( bufferedMessage ) {
239
+ socket . send ( JSON . stringify ( bufferedMessage ) )
240
+ bufferedMessage = null
237
241
}
238
242
} )
239
243
@@ -279,13 +283,18 @@ export function createWebSocketServer(
279
283
// sends the error payload before the client connection is established.
280
284
// If we have no open clients, buffer the error and send it to the next
281
285
// connected client.
282
- let bufferedError : ErrorPayload | null = null
286
+ // The same thing may happen when the optimizer runs fast enough to
287
+ // finish the bundling before the client connects.
288
+ let bufferedMessage : ErrorPayload | FullReloadPayload | null = null
283
289
284
290
const normalizedHotChannel = normalizeHotChannel (
285
291
{
286
292
send ( payload ) {
287
- if ( payload . type === 'error' && ! wss . clients . size ) {
288
- bufferedError = payload
293
+ if (
294
+ ( payload . type === 'error' || payload . type === 'full-reload' ) &&
295
+ ! wss . clients . size
296
+ ) {
297
+ bufferedMessage = payload
289
298
return
290
299
}
291
300
0 commit comments