Skip to content

Commit 56ec256

Browse files
Copilotsapphi-red
andauthored
perf: early return in getLocalhostAddressIfDiffersFromDNS when DNS order is verbatim (#22151)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
1 parent bdc53ab commit 56ec256

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

packages/vite/src/node/utils.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -922,17 +922,21 @@ export function unique<T>(arr: T[]): T[] {
922922
* Even if defaultResultOrder is `ipv4first`, `dns.lookup` result maybe same.
923923
* For example, when IPv6 is not supported on that machine/network.
924924
*/
925-
export async function getLocalhostAddressIfDiffersFromDNS(): Promise<
926-
string | undefined
927-
> {
928-
const [nodeResult, dnsResult] = await Promise.all([
925+
export function getLocalhostAddressIfDiffersFromDNS():
926+
| Promise<string | undefined>
927+
| undefined {
928+
if (dns.getDefaultResultOrder() === 'verbatim') {
929+
return undefined
930+
}
931+
return Promise.all([
929932
dns.lookup('localhost'),
930933
dns.lookup('localhost', { verbatim: true }),
931-
])
932-
const isSame =
933-
nodeResult.family === dnsResult.family &&
934-
nodeResult.address === dnsResult.address
935-
return isSame ? undefined : nodeResult.address
934+
]).then(([nodeResult, dnsResult]) => {
935+
const isSame =
936+
nodeResult.family === dnsResult.family &&
937+
nodeResult.address === dnsResult.address
938+
return isSame ? undefined : nodeResult.address
939+
})
936940
}
937941

938942
export function diffDnsOrderChange(

0 commit comments

Comments
 (0)