Skip to content

Commit 46d80f4

Browse files
committed
fix: allow hmr in all builds
close #2571
1 parent 3470308 commit 46d80f4

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed

packages/runtime-core/src/component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ export function handleSetupResult(
614614
) {
615615
if (isFunction(setupResult)) {
616616
// setup returned an inline render function
617-
if (!__BROWSER__ && (instance.type as ComponentOptions).__ssrInlineRender) {
617+
if (__NODE_JS__ && (instance.type as ComponentOptions).__ssrInlineRender) {
618618
// when the function's name is `ssrRender` (compiled by SFC inline mode),
619619
// set it as ssrRender instead.
620620
instance.ssrRender = setupResult

packages/runtime-core/src/customFormatter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { ComponentInternalInstance, ComponentOptions } from './component'
44
import { ComponentPublicInstance } from './componentPublicInstance'
55

66
export function initCustomFormatter() {
7-
if (!__DEV__ || !__BROWSER__) {
7+
/* eslint-disable no-restricted-globals */
8+
if (!__DEV__ || typeof window === 'undefined') {
89
return
910
}
1011

@@ -189,7 +190,6 @@ export function initCustomFormatter() {
189190
return `Ref`
190191
}
191192

192-
/* eslint-disable no-restricted-globals */
193193
if ((window as any).devtoolsFormatters) {
194194
;(window as any).devtoolsFormatters.push(formatter)
195195
} else {

packages/runtime-core/src/hmr.ts

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

packages/runtime-core/src/renderer.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ function baseCreateRenderer(
889889
invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate')
890890
}
891891

892-
if (__DEV__ && (__BROWSER__ || __TEST__) && isHmrUpdating) {
892+
if (__DEV__ && isHmrUpdating) {
893893
// HMR updated, force full diff
894894
patchFlag = 0
895895
optimized = false
@@ -990,12 +990,7 @@ function baseCreateRenderer(
990990
parentSuspense,
991991
areChildrenSVG
992992
)
993-
if (
994-
__DEV__ &&
995-
(__BROWSER__ || __TEST__) &&
996-
parentComponent &&
997-
parentComponent.type.__hmrId
998-
) {
993+
if (__DEV__ && parentComponent && parentComponent.type.__hmrId) {
999994
traverseStaticChildren(n1, n2)
1000995
}
1001996
} else if (!optimized) {
@@ -1248,7 +1243,7 @@ function baseCreateRenderer(
12481243
parentSuspense
12491244
))
12501245

1251-
if (__DEV__ && (__BROWSER__ || __TEST__) && instance.type.__hmrId) {
1246+
if (__DEV__ && instance.type.__hmrId) {
12521247
registerHMR(instance)
12531248
}
12541249

@@ -2122,7 +2117,7 @@ function baseCreateRenderer(
21222117
parentSuspense: SuspenseBoundary | null,
21232118
doRemove?: boolean
21242119
) => {
2125-
if (__DEV__ && (__BROWSER__ || __TEST__) && instance.type.__hmrId) {
2120+
if (__DEV__ && instance.type.__hmrId) {
21262121
unregisterHMR(instance)
21272122
}
21282123

0 commit comments

Comments
 (0)