@@ -10,7 +10,11 @@ import colors from 'picocolors'
10
10
import type { WebSocket as WebSocketRaw } from 'ws'
11
11
import { WebSocketServer as WebSocketServerRaw_ } from 'ws'
12
12
import type { WebSocket as WebSocketTypes } from 'dep-types/ws'
13
- import type { ErrorPayload , HotPayload } from 'types/hmrPayload'
13
+ import type {
14
+ ErrorPayload ,
15
+ FullReloadPayload ,
16
+ HotPayload ,
17
+ } from 'types/hmrPayload'
14
18
import type { InferCustomEventPayload } from 'types/customEvent'
15
19
import type { ResolvedConfig } from '..'
16
20
import { isObject } from '../utils'
@@ -295,9 +299,9 @@ export function createWebSocketServer(
295
299
} )
296
300
} )
297
301
socket . send ( JSON . stringify ( { type : 'connected' } ) )
298
- if ( bufferedError ) {
299
- socket . send ( JSON . stringify ( bufferedError ) )
300
- bufferedError = null
302
+ if ( bufferedMessage ) {
303
+ socket . send ( JSON . stringify ( bufferedMessage ) )
304
+ bufferedMessage = null
301
305
}
302
306
} )
303
307
@@ -343,13 +347,18 @@ export function createWebSocketServer(
343
347
// sends the error payload before the client connection is established.
344
348
// If we have no open clients, buffer the error and send it to the next
345
349
// connected client.
346
- let bufferedError : ErrorPayload | null = null
350
+ // The same thing may happen when the optimizer runs fast enough to
351
+ // finish the bundling before the client connects.
352
+ let bufferedMessage : ErrorPayload | FullReloadPayload | null = null
347
353
348
354
const normalizedHotChannel = normalizeHotChannel (
349
355
{
350
356
send ( payload ) {
351
- if ( payload . type === 'error' && ! wss . clients . size ) {
352
- bufferedError = payload
357
+ if (
358
+ ( payload . type === 'error' || payload . type === 'full-reload' ) &&
359
+ ! wss . clients . size
360
+ ) {
361
+ bufferedMessage = payload
353
362
return
354
363
}
355
364
0 commit comments