Skip to content

Commit

Permalink
fix: allow hmr in all builds
Browse files Browse the repository at this point in the history
close #2571
  • Loading branch information
yyx990803 committed Nov 27, 2020
1 parent 3470308 commit 46d80f4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ export function handleSetupResult(
) {
if (isFunction(setupResult)) {
// setup returned an inline render function
if (!__BROWSER__ && (instance.type as ComponentOptions).__ssrInlineRender) {
if (__NODE_JS__ && (instance.type as ComponentOptions).__ssrInlineRender) {
// when the function's name is `ssrRender` (compiled by SFC inline mode),
// set it as ssrRender instead.
instance.ssrRender = setupResult
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-core/src/customFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { ComponentInternalInstance, ComponentOptions } from './component'
import { ComponentPublicInstance } from './componentPublicInstance'

export function initCustomFormatter() {
if (!__DEV__ || !__BROWSER__) {
/* eslint-disable no-restricted-globals */
if (!__DEV__ || typeof window === 'undefined') {
return
}

Expand Down Expand Up @@ -189,7 +190,6 @@ export function initCustomFormatter() {
return `Ref`
}

/* eslint-disable no-restricted-globals */
if ((window as any).devtoolsFormatters) {
;(window as any).devtoolsFormatters.push(formatter)
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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__ && (__BROWSER__ || __TEST__)) {
if (__DEV__) {
const globalObject: any =
typeof global !== 'undefined'
? global
Expand Down
13 changes: 4 additions & 9 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ function baseCreateRenderer(
invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate')
}

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

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

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

Expand Down

0 comments on commit 46d80f4

Please sign in to comment.