From 0a09499f0160e4d5a6f324da1153ad545df69c2d Mon Sep 17 00:00:00 2001 From: patak Date: Wed, 29 Mar 2023 17:25:50 +0200 Subject: [PATCH 1/2] perf: avoid new URL() in hot path --- packages/vite/src/node/server/moduleGraph.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/server/moduleGraph.ts b/packages/vite/src/node/server/moduleGraph.ts index 4db3bcbca9a0f4..0ee5ec86ba840f 100644 --- a/packages/vite/src/node/server/moduleGraph.ts +++ b/packages/vite/src/node/server/moduleGraph.ts @@ -252,9 +252,11 @@ export class ModuleGraph { !url.startsWith(`virtual:`) ) { const ext = extname(cleanUrl(resolvedId)) - const { pathname, search, hash } = new URL(url, 'relative://') - if (ext && !pathname!.endsWith(ext)) { - url = pathname + ext + search + hash + if (ext) { + const pathname = cleanUrl(url) + if (!pathname.endsWith(ext)) { + url = pathname + ext + url.slice(pathname.length) + } } } return [url, resolvedId, resolved?.meta] From 3c962b2c4f4272b58d49edd2fb0cd6596633bb4c Mon Sep 17 00:00:00 2001 From: patak Date: Wed, 29 Mar 2023 20:24:07 +0200 Subject: [PATCH 2/2] chore: update comment --- packages/vite/src/node/server/moduleGraph.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/server/moduleGraph.ts b/packages/vite/src/node/server/moduleGraph.ts index 0ee5ec86ba840f..434d89b52d2cdc 100644 --- a/packages/vite/src/node/server/moduleGraph.ts +++ b/packages/vite/src/node/server/moduleGraph.ts @@ -239,7 +239,7 @@ export class ModuleGraph { } // for incoming urls, it is important to: - // 1. remove the HMR timestamp query (?t=xxxx) + // 1. remove the HMR timestamp query (?t=xxxx) and the ?import query // 2. resolve its extension so that urls with or without extension all map to // the same module async resolveUrl(url: string, ssr?: boolean): Promise {