From 32712668f6586734afa592384e325e9a8b528fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Fri, 24 Jun 2022 22:27:14 +0900 Subject: [PATCH] fix(hmr): __HMR_PORT__ should not be `'undefined'` (#8761) --- packages/vite/src/client/client.ts | 2 +- packages/vite/src/node/plugins/clientInjections.ts | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/vite/src/client/client.ts b/packages/vite/src/client/client.ts index ceccdf345fbce4..509b5048da6d47 100644 --- a/packages/vite/src/client/client.ts +++ b/packages/vite/src/client/client.ts @@ -9,7 +9,7 @@ import '@vite/env' declare const __BASE__: string declare const __HMR_PROTOCOL__: string | null declare const __HMR_HOSTNAME__: string | null -declare const __HMR_PORT__: string | null +declare const __HMR_PORT__: number | null declare const __HMR_DIRECT_TARGET__: string declare const __HMR_BASE__: string declare const __HMR_TIMEOUT__: number diff --git a/packages/vite/src/node/plugins/clientInjections.ts b/packages/vite/src/node/plugins/clientInjections.ts index d63c72d6143216..4eb1654d09d7a8 100644 --- a/packages/vite/src/node/plugins/clientInjections.ts +++ b/packages/vite/src/node/plugins/clientInjections.ts @@ -26,11 +26,9 @@ export function clientInjectionsPlugin(config: ResolvedConfig): Plugin { // hmr.clientPort -> hmr.port // -> (24678 if middleware mode) -> new URL(import.meta.url).port - let port = hmrConfig - ? String(hmrConfig.clientPort || hmrConfig.port) - : null + let port = hmrConfig?.clientPort || hmrConfig?.port || null if (config.server.middlewareMode) { - port ||= '24678' + port ||= 24678 } const devBase = config.base