fix: allow hmr in all builds

close #2571
This commit is contained in:
Evan You 2020-11-27 10:34:45 -05:00
parent 34703082fd
commit 46d80f4d58
4 changed files with 8 additions and 13 deletions

View File

@ -614,7 +614,7 @@ export function handleSetupResult(
) { ) {
if (isFunction(setupResult)) { if (isFunction(setupResult)) {
// setup returned an inline render function // 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), // when the function's name is `ssrRender` (compiled by SFC inline mode),
// set it as ssrRender instead. // set it as ssrRender instead.
instance.ssrRender = setupResult instance.ssrRender = setupResult

View File

@ -4,7 +4,8 @@ import { ComponentInternalInstance, ComponentOptions } from './component'
import { ComponentPublicInstance } from './componentPublicInstance' import { ComponentPublicInstance } from './componentPublicInstance'
export function initCustomFormatter() { export function initCustomFormatter() {
if (!__DEV__ || !__BROWSER__) { /* eslint-disable no-restricted-globals */
if (!__DEV__ || typeof window === 'undefined') {
return return
} }
@ -189,7 +190,6 @@ export function initCustomFormatter() {
return `Ref` return `Ref`
} }
/* eslint-disable no-restricted-globals */
if ((window as any).devtoolsFormatters) { if ((window as any).devtoolsFormatters) {
;(window as any).devtoolsFormatters.push(formatter) ;(window as any).devtoolsFormatters.push(formatter)
} else { } else {

View File

@ -26,7 +26,7 @@ export interface HMRRuntime {
// it easier to be used in toolings like vue-loader // 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 // 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. // to be set so that its instances can be registered / removed.
if (__DEV__ && (__BROWSER__ || __TEST__)) { if (__DEV__) {
const globalObject: any = const globalObject: any =
typeof global !== 'undefined' typeof global !== 'undefined'
? global ? global

View File

@ -889,7 +889,7 @@ function baseCreateRenderer(
invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate') invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate')
} }
if (__DEV__ && (__BROWSER__ || __TEST__) && isHmrUpdating) { if (__DEV__ && isHmrUpdating) {
// HMR updated, force full diff // HMR updated, force full diff
patchFlag = 0 patchFlag = 0
optimized = false optimized = false
@ -990,12 +990,7 @@ function baseCreateRenderer(
parentSuspense, parentSuspense,
areChildrenSVG areChildrenSVG
) )
if ( if (__DEV__ && parentComponent && parentComponent.type.__hmrId) {
__DEV__ &&
(__BROWSER__ || __TEST__) &&
parentComponent &&
parentComponent.type.__hmrId
) {
traverseStaticChildren(n1, n2) traverseStaticChildren(n1, n2)
} }
} else if (!optimized) { } else if (!optimized) {
@ -1248,7 +1243,7 @@ function baseCreateRenderer(
parentSuspense parentSuspense
)) ))
if (__DEV__ && (__BROWSER__ || __TEST__) && instance.type.__hmrId) { if (__DEV__ && instance.type.__hmrId) {
registerHMR(instance) registerHMR(instance)
} }
@ -2122,7 +2117,7 @@ function baseCreateRenderer(
parentSuspense: SuspenseBoundary | null, parentSuspense: SuspenseBoundary | null,
doRemove?: boolean doRemove?: boolean
) => { ) => {
if (__DEV__ && (__BROWSER__ || __TEST__) && instance.type.__hmrId) { if (__DEV__ && instance.type.__hmrId) {
unregisterHMR(instance) unregisterHMR(instance)
} }