Skip to content

Commit 6a75773

Browse files
committed
fix: buffer full reload messages
1 parent a0c4fb7 commit 6a75773

File tree

1 file changed

+16
-7
lines changed
  • packages/vite/src/node/server

1 file changed

+16
-7
lines changed

packages/vite/src/node/server/ws.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import colors from 'picocolors'
1010
import type { WebSocket as WebSocketRaw } from 'ws'
1111
import { WebSocketServer as WebSocketServerRaw_ } from 'ws'
1212
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'
1418
import type { InferCustomEventPayload } from 'types/customEvent'
1519
import type { ResolvedConfig } from '..'
1620
import { isObject } from '../utils'
@@ -295,9 +299,9 @@ export function createWebSocketServer(
295299
})
296300
})
297301
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
301305
}
302306
})
303307

@@ -343,13 +347,18 @@ export function createWebSocketServer(
343347
// sends the error payload before the client connection is established.
344348
// If we have no open clients, buffer the error and send it to the next
345349
// 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
347353

348354
const normalizedHotChannel = normalizeHotChannel(
349355
{
350356
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
353362
return
354363
}
355364

0 commit comments

Comments
 (0)