From 3162b3ceeacb8664539e12daf680cc536fa90cc8 Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Thu, 3 Aug 2023 10:07:27 -0700 Subject: [PATCH] fix: support vite HMR source replacements Fixes #1761 --- CHANGELOG.md | 1 + src/adapter/sources.ts | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c391de82a..c4ef8ae29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This changelog records changes to stable releases since 1.50.2. "TBA" changes he ## Nightly (only) - fix: child processes from extension host not getting spawned during debug +- fix: support vite HMR source replacements ([#1761](https://github.com/microsoft/vscode-js-debug/issues/1761)) - fix: immediately log stdout/err unless EXT is encountered ([vscode#181785](https://github.com/microsoft/vscode/issues/181785)) - fix: hint content type for sources with query strings ([vscode#181746](https://github.com/microsoft/vscode/issues/181746)) diff --git a/src/adapter/sources.ts b/src/adapter/sources.ts index 747002dbc..071358b4f 100644 --- a/src/adapter/sources.ts +++ b/src/adapter/sources.ts @@ -85,8 +85,10 @@ export type SourceMapTimeouts = { output: number; }; +const viteHMRPattern = /\?t=[0-9]+$/; + /** Gets whether the URL is a compiled source containing a webpack HMR */ -const isWebpackHMR = (url: string) => url.endsWith('.hot-update.js'); +const isHMR = (url: string) => url.endsWith('.hot-update.js') || viteHMRPattern.test(url); const defaultTimeouts: SourceMapTimeouts = { load: 0, @@ -1115,9 +1117,8 @@ export class SourceContainer { } if (existing) { - // In the case of a Webpack HMR, remove the old source entirely and - // replace it with the new one. - if (isWebpackHMR(compiled.url)) { + // In the case of an HMR, remove the old source entirely and replace it with the new one. + if (isHMR(compiled.url)) { this.removeSource(existing); } else { existing.compiledToSourceUrl.set(compiled, url);