Skip to content

Commit

Permalink
fix: print urls when dns order change (#12261)
Browse files Browse the repository at this point in the history
  • Loading branch information
btea authored Mar 11, 2023
1 parent 4a42c90 commit e57cacf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import type { InlineConfig, ResolvedConfig } from '../config'
import { isDepsOptimizerEnabled, resolveConfig } from '../config'
import {
diffDnsOrderChange,
isParentDirectory,
mergeConfig,
normalizePath,
Expand Down Expand Up @@ -814,7 +815,7 @@ async function restartServer(server: ViteDevServer) {
global.__vite_start_time = performance.now()
const { port: prevPort, host: prevHost } = server.config.server
const shortcutsOptions: BindShortcutsOptions = server._shortcutsOptions

const oldUrls = server.resolvedUrls
await server.close()

let inlineConfig = server.config.inlineConfig
Expand Down Expand Up @@ -850,7 +851,8 @@ async function restartServer(server: ViteDevServer) {
logger.info('server restarted.', { timestamp: true })
if (
(port ?? DEFAULT_DEV_PORT) !== (prevPort ?? DEFAULT_DEV_PORT) ||
host !== prevHost
host !== prevHost ||
diffDnsOrderChange(oldUrls, newServer.resolvedUrls)
) {
logger.info('')
server.printUrls()
Expand Down
15 changes: 14 additions & 1 deletion packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from './constants'
import type { DepOptimizationConfig } from './optimizer'
import type { ResolvedConfig } from './config'
import type { ResolvedServerUrls } from './server'
import type { ResolvedServerUrls, ViteDevServer } from './server'
import type { CommonServerOptions } from '.'

/**
Expand Down Expand Up @@ -815,6 +815,19 @@ export async function getLocalhostAddressIfDiffersFromDNS(): Promise<
return isSame ? undefined : nodeResult.address
}

export function diffDnsOrderChange(
oldUrls: ViteDevServer['resolvedUrls'],
newUrls: ViteDevServer['resolvedUrls'],
): boolean {
return !(
oldUrls === newUrls ||
(oldUrls &&
newUrls &&
arrayEqual(oldUrls.local, newUrls.local) &&
arrayEqual(oldUrls.network, newUrls.network))
)
}

export interface Hostname {
/** undefined sets the default behaviour of server.listen */
host: string | undefined
Expand Down

0 comments on commit e57cacf

Please sign in to comment.