Skip to content

Commit

Permalink
fix(hmr): fix hmr updates for reused hoisted trees
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jul 15, 2020
1 parent 81e82e7 commit 5f61aa0
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,31 @@ function baseCreateRenderer(
optimized
)
} else {
patchElement(n1, n2, parentComponent, parentSuspense, isSVG, optimized)
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)
}
}
}

Expand Down

0 comments on commit 5f61aa0

Please sign in to comment.