1
1
/* eslint-disable no-restricted-globals */
2
2
import {
3
+ Component ,
3
4
ComponentInternalInstance ,
4
5
ComponentOptions ,
5
6
InternalRenderFunction
6
7
} from './component'
7
8
import { queueJob , queuePostFlushCb } from './scheduler'
8
9
import { extend } from '@vue/shared'
9
10
11
+ export let isHmrUpdating = false
12
+
13
+ export const hmrDirtyComponents = new Set < Component > ( )
14
+
10
15
export interface HMRRuntime {
11
16
createRecord : typeof createRecord
12
17
rerender : typeof rerender
@@ -72,9 +77,9 @@ function rerender(id: string, newRender?: Function) {
72
77
}
73
78
instance . renderCache = [ ]
74
79
// this flag forces child components with slot content to update
75
- instance . hmrUpdated = true
80
+ isHmrUpdating = true
76
81
instance . update ( )
77
- instance . hmrUpdated = false
82
+ isHmrUpdating = false
78
83
} )
79
84
}
80
85
@@ -85,7 +90,7 @@ function reload(id: string, newComp: ComponentOptions) {
85
90
// updates
86
91
Array . from ( record ) . forEach ( instance => {
87
92
const comp = instance . type
88
- if ( ! comp . __hmrUpdated ) {
93
+ if ( ! hmrDirtyComponents . has ( comp ) ) {
89
94
// 1. Update existing comp definition to match new one
90
95
extend ( comp , newComp )
91
96
for ( const key in comp ) {
@@ -95,10 +100,10 @@ function reload(id: string, newComp: ComponentOptions) {
95
100
}
96
101
// 2. Mark component dirty. This forces the renderer to replace the component
97
102
// on patch.
98
- comp . __hmrUpdated = true
103
+ hmrDirtyComponents . add ( comp )
99
104
// 3. Make sure to unmark the component after the reload.
100
105
queuePostFlushCb ( ( ) => {
101
- comp . __hmrUpdated = false
106
+ hmrDirtyComponents . delete ( comp )
102
107
} )
103
108
}
104
109
0 commit comments