@@ -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'
@@ -297,9 +301,9 @@ export function createWebSocketServer(
297
301
} )
298
302
} )
299
303
socket . send ( JSON . stringify ( { type : 'connected' } ) )
300
- if ( bufferedError ) {
301
- socket . send ( JSON . stringify ( bufferedError ) )
302
- bufferedError = null
304
+ if ( bufferedMessage ) {
305
+ socket . send ( JSON . stringify ( bufferedMessage ) )
306
+ bufferedMessage = null
303
307
}
304
308
} )
305
309
@@ -345,13 +349,18 @@ export function createWebSocketServer(
345
349
// sends the error payload before the client connection is established.
346
350
// If we have no open clients, buffer the error and send it to the next
347
351
// connected client.
348
- let bufferedError : ErrorPayload | null = null
352
+ // The same thing may happen when the optimizer runs fast enough to
353
+ // finish the bundling before the client connects.
354
+ let bufferedMessage : ErrorPayload | FullReloadPayload | null = null
349
355
350
356
const normalizedHotChannel = normalizeHotChannel (
351
357
{
352
358
send ( payload ) {
353
- if ( payload . type === 'error' && ! wss . clients . size ) {
354
- bufferedError = payload
359
+ if (
360
+ ( payload . type === 'error' || payload . type === 'full-reload' ) &&
361
+ ! wss . clients . size
362
+ ) {
363
+ bufferedMessage = payload
355
364
return
356
365
}
357
366
0 commit comments