fix(hmr): prevent __VUE_HMR_RUNTIME__ from being overwritten by vue runtime in 3rd-party libraries (#13817)

close vitejs/vite-plugin-vue#644
This commit is contained in:
edison 2025-09-02 17:10:30 +08:00 committed by GitHub
parent 8696e346b4
commit 1392734ae5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 5 deletions

View File

@ -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__ = {
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<