Skip to content

Commit

Permalink
perf: do not enable hmr in non-browser envs
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Oct 6, 2020
1 parent 5c3e8e9 commit cf2c9f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/runtime-core/src/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface HMRRuntime {
// it easier to be used in toolings like vue-loader
// 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__) {
if (__DEV__ && (__BROWSER__ || __TEST__)) {
const globalObject: any =
typeof global !== 'undefined'
? global
Expand Down
13 changes: 9 additions & 4 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ function baseCreateRenderer(
invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate')
}

if (__DEV__ && isHmrUpdating) {
if (__DEV__ && (__BROWSER__ || __TEST__) && isHmrUpdating) {
// HMR updated, force full diff
patchFlag = 0
optimized = false
Expand Down Expand Up @@ -986,7 +986,12 @@ function baseCreateRenderer(
parentSuspense,
areChildrenSVG
)
if (__DEV__ && parentComponent && parentComponent.type.__hmrId) {
if (
__DEV__ &&
(__BROWSER__ || __TEST__) &&
parentComponent &&
parentComponent.type.__hmrId
) {
traverseStaticChildren(n1, n2)
}
} else if (!optimized) {
Expand Down Expand Up @@ -1238,7 +1243,7 @@ function baseCreateRenderer(
parentSuspense
))

if (__DEV__ && instance.type.__hmrId) {
if (__DEV__ && (__BROWSER__ || __TEST__) && instance.type.__hmrId) {
registerHMR(instance)
}

Expand Down Expand Up @@ -2109,7 +2114,7 @@ function baseCreateRenderer(
parentSuspense: SuspenseBoundary | null,
doRemove?: boolean
) => {
if (__DEV__ && instance.type.__hmrId) {
if (__DEV__ && (__BROWSER__ || __TEST__) && instance.type.__hmrId) {
unregisterHMR(instance)
}

Expand Down

0 comments on commit cf2c9f6

Please sign in to comment.