test: test hot module replacement

This commit is contained in:
Evan You
2019-12-16 17:57:34 -05:00
parent f194aa0eea
commit 8ea2101553
4 changed files with 166 additions and 4 deletions

View File

@@ -5,6 +5,12 @@ import {
} from './component'
import { queueJob, queuePostFlushCb } from './scheduler'
export interface HMRRuntime {
createRecord: typeof createRecord
rerender: typeof rerender
reload: typeof reload
}
// Expose the HMR runtime on the global object
// This makes it entirely tree-shakable without polluting the exports and makes
// it easier to be used in toolings like vue-loader
@@ -24,7 +30,7 @@ if (__BUNDLER__ && __DEV__) {
createRecord: tryWrap(createRecord),
rerender: tryWrap(rerender),
reload: tryWrap(reload)
}
} as HMRRuntime
}
interface HMRRecord {

View File

@@ -130,3 +130,4 @@ export {
DirectiveArguments
} from './directives'
export { SuspenseBoundary } from './components/Suspense'
export { HMRRuntime } from './hmr'

View File

@@ -475,6 +475,7 @@ export function createRenderer<
// HMR updated, force full diff
patchFlag = 0
optimized = false
dynamicChildren = null
}
if (patchFlag > 0) {
@@ -593,6 +594,9 @@ export function createRenderer<
) {
for (let i = 0; i < newChildren.length; i++) {
const oldVNode = oldChildren[i]
if (!oldVNode) {
debugger
}
patch(
oldVNode,
newChildren[i],
@@ -682,7 +686,7 @@ export function createRenderer<
? n1.anchor
: hostCreateComment(showID ? `fragment-${devFragmentID}-end` : ''))!
let { patchFlag } = n2
let { patchFlag, dynamicChildren } = n2
if (patchFlag > 0) {
optimized = true
}
@@ -691,6 +695,7 @@ export function createRenderer<
// HMR updated, force full diff
patchFlag = 0
optimized = false
dynamicChildren = null
}
if (n1 == null) {
@@ -712,12 +717,12 @@ export function createRenderer<
optimized
)
} else {
if (patchFlag & PatchFlags.STABLE_FRAGMENT && n2.dynamicChildren) {
if (patchFlag & PatchFlags.STABLE_FRAGMENT && dynamicChildren != null) {
// a stable fragment (template root or <template v-for>) doesn't need to
// patch children order, but it may contain dynamicChildren.
patchBlockChildren(
n1.dynamicChildren!,
n2.dynamicChildren,
dynamicChildren,
container,
parentComponent,
parentSuspense,