From 9af1517e47f66bb793447d998cf1a4d2fa3ef758 Mon Sep 17 00:00:00 2001 From: CHOYSEN Date: Tue, 9 Feb 2021 22:10:25 +0800 Subject: [PATCH] fix: do not open browser when restarting server (#1952) --- packages/vite/src/node/server/hmr.ts | 2 +- packages/vite/src/node/server/index.ts | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/server/hmr.ts b/packages/vite/src/node/server/hmr.ts index f5ffa9a9fdc82e..5ba27c3c8b68dd 100644 --- a/packages/vite/src/node/server/hmr.ts +++ b/packages/vite/src/node/server/hmr.ts @@ -421,7 +421,7 @@ async function restartServer(server: ViteDevServer) { } } if (!server.config.server.middlewareMode) { - await server.listen() + await server.listen(undefined, true) } else { server.config.logger.info('server restarted.', { timestamp: true }) } diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index b2e2d5709e52ca..61d08eac01a58f 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -220,7 +220,7 @@ export interface ViteDevServer { /** * Start the server. */ - listen(port?: number): Promise + listen(port?: number, isRestart?: boolean): Promise /** * Stop the server. */ @@ -321,8 +321,8 @@ export async function createServer( e.stack = ssrRewriteStacktrace(e.stack, moduleGraph) } }, - listen(port?: number) { - return startServer(server, port) + listen(port?: number, isRestart?: boolean) { + return startServer(server, port, isRestart) }, async close() { await Promise.all([ @@ -510,7 +510,8 @@ export async function createServer( async function startServer( server: ViteDevServer, - inlinePort?: number + inlinePort?: number, + isRestart: boolean = false ): Promise { const httpServer = server.httpServer if (!httpServer) { @@ -595,7 +596,7 @@ async function startServer( }) } - if (options.open) { + if (options.open && !isRestart) { const path = typeof options.open === 'string' ? options.open : base openBrowser( `${protocol}://${hostname}:${port}${path}`,