Skip to content

Commit cf2c9f6

Browse files
committed
perf: do not enable hmr in non-browser envs
1 parent 5c3e8e9 commit cf2c9f6

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

packages/runtime-core/src/hmr.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface HMRRuntime {
2525
// it easier to be used in toolings like vue-loader
2626
// Note: for a component to be eligible for HMR it also needs the __hmrId option
2727
// to be set so that its instances can be registered / removed.
28-
if (__DEV__) {
28+
if (__DEV__ && (__BROWSER__ || __TEST__)) {
2929
const globalObject: any =
3030
typeof global !== 'undefined'
3131
? global

packages/runtime-core/src/renderer.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ function baseCreateRenderer(
885885
invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate')
886886
}
887887

888-
if (__DEV__ && isHmrUpdating) {
888+
if (__DEV__ && (__BROWSER__ || __TEST__) && isHmrUpdating) {
889889
// HMR updated, force full diff
890890
patchFlag = 0
891891
optimized = false
@@ -986,7 +986,12 @@ function baseCreateRenderer(
986986
parentSuspense,
987987
areChildrenSVG
988988
)
989-
if (__DEV__ && parentComponent && parentComponent.type.__hmrId) {
989+
if (
990+
__DEV__ &&
991+
(__BROWSER__ || __TEST__) &&
992+
parentComponent &&
993+
parentComponent.type.__hmrId
994+
) {
990995
traverseStaticChildren(n1, n2)
991996
}
992997
} else if (!optimized) {
@@ -1238,7 +1243,7 @@ function baseCreateRenderer(
12381243
parentSuspense
12391244
))
12401245

1241-
if (__DEV__ && instance.type.__hmrId) {
1246+
if (__DEV__ && (__BROWSER__ || __TEST__) && instance.type.__hmrId) {
12421247
registerHMR(instance)
12431248
}
12441249

@@ -2109,7 +2114,7 @@ function baseCreateRenderer(
21092114
parentSuspense: SuspenseBoundary | null,
21102115
doRemove?: boolean
21112116
) => {
2112-
if (__DEV__ && instance.type.__hmrId) {
2117+
if (__DEV__ && (__BROWSER__ || __TEST__) && instance.type.__hmrId) {
21132118
unregisterHMR(instance)
21142119
}
21152120

0 commit comments

Comments
 (0)