Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 21 additions & 23 deletions packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,32 +542,30 @@ export async function reloadOnTsconfigChange(
changedFile: string,
): Promise<void> {
// 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')) {
const cache = getTSConfigResolutionCache(server.config)
if (changedFile.endsWith('/tsconfig.json')) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line actually should have || cache.hasParseResult(changedFile) like the condition in v7:

if (
changedFile.endsWith('/tsconfig.json') ||
cache.hasParseResult(changedFile)
) {

The fix is blocked by oxc-project/oxc-resolver#1011, but after we have that, the condition should be added.

So if the performance difference isn't significant, I'll prefer to keep the code as-is.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh, that makes sense!

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: '*',
})
}
}
Loading