From 2f54d530a62b55fbf2b86f5acfeb9b595481f181 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Fri, 29 Aug 2025 23:38:01 +0900 Subject: [PATCH 1/2] fix(hmr): wait for `import.meta.hot.prune` callbacks to complete before running other HMRs --- packages/vite/src/shared/hmr.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/shared/hmr.ts b/packages/vite/src/shared/hmr.ts index 85b0916c5f4f5f..4042d259baca92 100644 --- a/packages/vite/src/shared/hmr.ts +++ b/packages/vite/src/shared/hmr.ts @@ -219,12 +219,14 @@ export class HMRClient { if (disposer) return disposer(this.dataMap.get(path)) }), ) - paths.forEach((path) => { - const fn = this.pruneMap.get(path) - if (fn) { - fn(this.dataMap.get(path)) - } - }) + await Promise.all( + paths.map((path) => { + const fn = this.pruneMap.get(path) + if (fn) { + fn(this.dataMap.get(path)) + } + }), + ) } protected warnFailedUpdate(err: Error, path: string | string[]): void { From 437dc1ccc8538470de1dd28da57f5d35ef327f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0?= Date: Mon, 8 Sep 2025 19:22:39 +0900 Subject: [PATCH 2/2] fix: return promise properly Co-authored-by: Bjorn Lu --- packages/vite/src/shared/hmr.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/shared/hmr.ts b/packages/vite/src/shared/hmr.ts index 4042d259baca92..aa44ab5e48b0d2 100644 --- a/packages/vite/src/shared/hmr.ts +++ b/packages/vite/src/shared/hmr.ts @@ -223,7 +223,7 @@ export class HMRClient { paths.map((path) => { const fn = this.pruneMap.get(path) if (fn) { - fn(this.dataMap.get(path)) + return fn(this.dataMap.get(path)) } }), )