From ba723bddfc1b0fb804cb310254f9287f313bfee7 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 24 Apr 2026 15:56:29 +0100 Subject: [PATCH 1/2] perf(vite): narrow test for changed files in esbuild plugin --- packages/vite/src/node/plugins/esbuild.ts | 39 +++++++++++------------ 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index 3590e98dff4507..d589dc4d5089f2 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -542,32 +542,29 @@ export async function reloadOnTsconfigChange( changedFile: string, ): Promise { // any tsconfig.json that's added in the workspace could be closer to a code file than a previously cached one - // any json file in the tsconfig cache could have been used to compile ts - if (changedFile.endsWith('.json')) { + if (changedFile.endsWith('/tsconfig.json')) { const cache = getTSConfigResolutionCache(server.config) - if (changedFile.endsWith('/tsconfig.json')) { - server.config.logger.info( - `changed tsconfig file detected: ${changedFile} - Clearing cache and forcing full-reload to ensure TypeScript is compiled with updated config values.`, - { clear: server.config.clearScreen, timestamp: true }, - ) + server.config.logger.info( + `changed tsconfig file detected: ${changedFile} - Clearing cache and forcing full-reload to ensure TypeScript is compiled with updated config values.`, + { clear: server.config.clearScreen, timestamp: true }, + ) - // TODO: more finegrained invalidation than the nuclear option below + // TODO: more finegrained invalidation than the nuclear option below - // clear module graph to remove code compiled with outdated config - for (const environment of Object.values(server.environments)) { - environment.moduleGraph.invalidateAll() - } + // clear module graph to remove code compiled with outdated config + for (const environment of Object.values(server.environments)) { + environment.moduleGraph.invalidateAll() + } - // reset the cache so that recompile works with up2date configs - cache.clear() + // reset the cache so that recompile works with up2date configs + cache.clear() - // reload environments - for (const environment of Object.values(server.environments)) { - environment.hot.send({ - type: 'full-reload', - path: '*', - }) - } + // reload environments + for (const environment of Object.values(server.environments)) { + environment.hot.send({ + type: 'full-reload', + path: '*', + }) } } } From 22c87c2ba6639eea3d2245b02d05e53365185851 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 24 Apr 2026 15:57:51 +0100 Subject: [PATCH 2/2] refactor: early return --- packages/vite/src/node/plugins/esbuild.ts | 41 ++++++++++++----------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index d589dc4d5089f2..48fb3e6b6cc581 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -542,29 +542,30 @@ export async function reloadOnTsconfigChange( changedFile: string, ): Promise { // any tsconfig.json that's added in the workspace could be closer to a code file than a previously cached one - if (changedFile.endsWith('/tsconfig.json')) { - const cache = getTSConfigResolutionCache(server.config) - server.config.logger.info( - `changed tsconfig file detected: ${changedFile} - Clearing cache and forcing full-reload to ensure TypeScript is compiled with updated config values.`, - { clear: server.config.clearScreen, timestamp: true }, - ) + if (!changedFile.endsWith('/tsconfig.json')) { + return + } - // TODO: more finegrained invalidation than the nuclear option below + server.config.logger.info( + `changed tsconfig file detected: ${changedFile} - Clearing cache and forcing full-reload to ensure TypeScript is compiled with updated config values.`, + { clear: server.config.clearScreen, timestamp: true }, + ) - // clear module graph to remove code compiled with outdated config - for (const environment of Object.values(server.environments)) { - environment.moduleGraph.invalidateAll() - } + // TODO: more finegrained invalidation than the nuclear option below - // reset the cache so that recompile works with up2date configs - cache.clear() + // clear module graph to remove code compiled with outdated config + for (const environment of Object.values(server.environments)) { + environment.moduleGraph.invalidateAll() + } - // reload environments - for (const environment of Object.values(server.environments)) { - environment.hot.send({ - type: 'full-reload', - path: '*', - }) - } + // reset the cache so that recompile works with up2date configs + getTSConfigResolutionCache(server.config).clear() + + // reload environments + for (const environment of Object.values(server.environments)) { + environment.hot.send({ + type: 'full-reload', + path: '*', + }) } }