Skip to content

Commit 1392734

Browse files
authored
fix(hmr): prevent __VUE_HMR_RUNTIME__ from being overwritten by vue runtime in 3rd-party libraries (#13817)
close vitejs/vite-plugin-vue#644
1 parent 8696e34 commit 1392734

File tree

1 file changed

+11
-5
lines changed
  • packages/runtime-core/src

1 file changed

+11
-5
lines changed

packages/runtime-core/src/hmr.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@ export interface HMRRuntime {
3131
// Note: for a component to be eligible for HMR it also needs the __hmrId option
3232
// to be set so that its instances can be registered / removed.
3333
if (__DEV__) {
34-
getGlobalThis().__VUE_HMR_RUNTIME__ = {
35-
createRecord: tryWrap(createRecord),
36-
rerender: tryWrap(rerender),
37-
reload: tryWrap(reload),
38-
} as HMRRuntime
34+
const g = getGlobalThis()
35+
// vite-plugin-vue/issues/644, #13202
36+
// custom-element libraries bundle Vue to simplify usage outside Vue projects but
37+
// it overwrite __VUE_HMR_RUNTIME__, causing HMR to break.
38+
if (!g.__VUE_HMR_RUNTIME__) {
39+
g.__VUE_HMR_RUNTIME__ = {
40+
createRecord: tryWrap(createRecord),
41+
rerender: tryWrap(rerender),
42+
reload: tryWrap(reload),
43+
} as HMRRuntime
44+
}
3945
}
4046

4147
const map: Map<

0 commit comments

Comments
 (0)