Skip to content

Commit

Permalink
fix: do not open browser when restarting server (#1952)
Browse files Browse the repository at this point in the history
  • Loading branch information
CHOYSEN authored Feb 9, 2021
1 parent 0f692ce commit 9af1517
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down
11 changes: 6 additions & 5 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export interface ViteDevServer {
/**
* Start the server.
*/
listen(port?: number): Promise<ViteDevServer>
listen(port?: number, isRestart?: boolean): Promise<ViteDevServer>
/**
* Stop the server.
*/
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -510,7 +510,8 @@ export async function createServer(

async function startServer(
server: ViteDevServer,
inlinePort?: number
inlinePort?: number,
isRestart: boolean = false
): Promise<ViteDevServer> {
const httpServer = server.httpServer
if (!httpServer) {
Expand Down Expand Up @@ -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}`,
Expand Down

0 comments on commit 9af1517

Please sign in to comment.