Skip to content

Commit 5f61aa0

Browse files
committed
fix(hmr): fix hmr updates for reused hoisted trees
fix vitejs/vite#514
1 parent 81e82e7 commit 5f61aa0

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

packages/runtime-core/src/renderer.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,31 @@ function baseCreateRenderer(
638638
optimized
639639
)
640640
} else {
641-
patchElement(n1, n2, parentComponent, parentSuspense, isSVG, optimized)
641+
if (
642+
__DEV__ &&
643+
isHmrUpdating &&
644+
hostCloneNode !== undefined &&
645+
n2.patchFlag === PatchFlags.HOISTED
646+
) {
647+
// https://github.com/vitejs/vite/issues/514
648+
// reused hoisted trees are inserted with cloneNode
649+
// which makes them not patch-able. In production hoisted trees are
650+
// never patched (because they are not collected as dynamic nodes), but
651+
// they can be udpated during HMR. In this case just mount it as new
652+
// and remove the stale DOM tree.
653+
mountElement(
654+
n2,
655+
container,
656+
n1.el,
657+
parentComponent,
658+
parentSuspense,
659+
isSVG,
660+
optimized
661+
)
662+
hostRemove(n1.el!)
663+
} else {
664+
patchElement(n1, n2, parentComponent, parentSuspense, isSVG, optimized)
665+
}
642666
}
643667
}
644668

0 commit comments

Comments
 (0)