fix(hmr): fix hmr updates for reused hoisted trees

fix https://github.com/vitejs/vite/issues/514
This commit is contained in:
Evan You 2020-07-15 12:26:44 -04:00
parent 81e82e7d21
commit 5f61aa0f71

View File

@ -637,10 +637,34 @@ function baseCreateRenderer(
isSVG,
optimized
)
} else {
if (
__DEV__ &&
isHmrUpdating &&
hostCloneNode !== undefined &&
n2.patchFlag === PatchFlags.HOISTED
) {
// https://github.com/vitejs/vite/issues/514
// reused hoisted trees are inserted with cloneNode
// which makes them not patch-able. In production hoisted trees are
// never patched (because they are not collected as dynamic nodes), but
// they can be udpated during HMR. In this case just mount it as new
// and remove the stale DOM tree.
mountElement(
n2,
container,
n1.el,
parentComponent,
parentSuspense,
isSVG,
optimized
)
hostRemove(n1.el!)
} else {
patchElement(n1, n2, parentComponent, parentSuspense, isSVG, optimized)
}
}
}
const mountElement = (
vnode: VNode,