|
|
@@ -1,5 +1,6 @@
|
|
|
/* eslint-disable no-restricted-globals */
|
|
|
import {
|
|
|
+ Component,
|
|
|
ComponentInternalInstance,
|
|
|
ComponentOptions,
|
|
|
InternalRenderFunction
|
|
|
@@ -7,6 +8,10 @@ import {
|
|
|
import { queueJob, queuePostFlushCb } from './scheduler'
|
|
|
import { extend } from '@vue/shared'
|
|
|
|
|
|
+export let isHmrUpdating = false
|
|
|
+
|
|
|
+export const hmrDirtyComponents = new Set<Component>()
|
|
|
+
|
|
|
export interface HMRRuntime {
|
|
|
createRecord: typeof createRecord
|
|
|
rerender: typeof rerender
|
|
|
@@ -72,9 +77,9 @@ function rerender(id: string, newRender?: Function) {
|
|
|
}
|
|
|
instance.renderCache = []
|
|
|
// this flag forces child components with slot content to update
|
|
|
- instance.hmrUpdated = true
|
|
|
+ isHmrUpdating = true
|
|
|
instance.update()
|
|
|
- instance.hmrUpdated = false
|
|
|
+ isHmrUpdating = false
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -85,7 +90,7 @@ function reload(id: string, newComp: ComponentOptions) {
|
|
|
// updates
|
|
|
Array.from(record).forEach(instance => {
|
|
|
const comp = instance.type
|
|
|
- if (!comp.__hmrUpdated) {
|
|
|
+ if (!hmrDirtyComponents.has(comp)) {
|
|
|
// 1. Update existing comp definition to match new one
|
|
|
extend(comp, newComp)
|
|
|
for (const key in comp) {
|
|
|
@@ -95,10 +100,10 @@ function reload(id: string, newComp: ComponentOptions) {
|
|
|
}
|
|
|
// 2. Mark component dirty. This forces the renderer to replace the component
|
|
|
// on patch.
|
|
|
- comp.__hmrUpdated = true
|
|
|
+ hmrDirtyComponents.add(comp)
|
|
|
// 3. Make sure to unmark the component after the reload.
|
|
|
queuePostFlushCb(() => {
|
|
|
- comp.__hmrUpdated = false
|
|
|
+ hmrDirtyComponents.delete(comp)
|
|
|
})
|
|
|
}
|
|
|
|