From 1392734ae5d5a3b2be124753e198eafa324f6815 Mon Sep 17 00:00:00 2001 From: edison Date: Tue, 2 Sep 2025 17:10:30 +0800 Subject: [PATCH] fix(hmr): prevent __VUE_HMR_RUNTIME__ from being overwritten by vue runtime in 3rd-party libraries (#13817) close vitejs/vite-plugin-vue#644 --- packages/runtime-core/src/hmr.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/runtime-core/src/hmr.ts b/packages/runtime-core/src/hmr.ts index 4191a34f82..8f443de0cc 100644 --- a/packages/runtime-core/src/hmr.ts +++ b/packages/runtime-core/src/hmr.ts @@ -31,11 +31,17 @@ export interface HMRRuntime { // Note: for a component to be eligible for HMR it also needs the __hmrId option // to be set so that its instances can be registered / removed. if (__DEV__) { - getGlobalThis().__VUE_HMR_RUNTIME__ = { - createRecord: tryWrap(createRecord), - rerender: tryWrap(rerender), - reload: tryWrap(reload), - } as HMRRuntime + const g = getGlobalThis() + // vite-plugin-vue/issues/644, #13202 + // custom-element libraries bundle Vue to simplify usage outside Vue projects but + // it overwrite __VUE_HMR_RUNTIME__, causing HMR to break. + if (!g.__VUE_HMR_RUNTIME__) { + g.__VUE_HMR_RUNTIME__ = { + createRecord: tryWrap(createRecord), + rerender: tryWrap(rerender), + reload: tryWrap(reload), + } as HMRRuntime + } } const map: Map< -- 2.47.3