@@ -10,8 +10,7 @@ import {
1010 isSameVNodeType ,
1111 Static ,
1212 VNodeNormalizedRef ,
13- VNodeHook ,
14- isVNode
13+ VNodeHook
1514} from './vnode'
1615import {
1716 ComponentInternalInstance ,
@@ -639,31 +638,7 @@ function baseCreateRenderer(
639638 optimized
640639 )
641640 } else {
642- if (
643- __DEV__ &&
644- isHmrUpdating &&
645- hostCloneNode !== undefined &&
646- n2 . patchFlag === PatchFlags . HOISTED
647- ) {
648- // https://github.com/vitejs/vite/issues/514
649- // reused hoisted trees are inserted with cloneNode
650- // which makes them not patch-able. In production hoisted trees are
651- // never patched (because they are not collected as dynamic nodes), but
652- // they can be udpated during HMR. In this case just mount it as new
653- // and remove the stale DOM tree.
654- mountElement (
655- n2 ,
656- container ,
657- n1 . el ,
658- parentComponent ,
659- parentSuspense ,
660- isSVG ,
661- optimized
662- )
663- hostRemove ( n1 . el ! )
664- } else {
665- patchElement ( n1 , n2 , parentComponent , parentSuspense , isSVG , optimized )
666- }
641+ patchElement ( n1 , n2 , parentComponent , parentSuspense , isSVG , optimized )
667642 }
668643 }
669644
@@ -688,13 +663,15 @@ function baseCreateRenderer(
688663 dirs
689664 } = vnode
690665 if (
666+ ! __DEV__ &&
691667 vnode . el &&
692668 hostCloneNode !== undefined &&
693669 patchFlag === PatchFlags . HOISTED
694670 ) {
695671 // If a vnode has non-null el, it means it's being reused.
696672 // Only static vnodes can be reused, so its mounted DOM nodes should be
697673 // exactly the same, and we can simply do a clone here.
674+ // only do this in production since cloned trees cannot be HMR updated.
698675 el = vnode . el = hostCloneNode ( vnode . el )
699676 } else {
700677 el = vnode . el = hostCreateElement (
@@ -2107,14 +2084,11 @@ function baseCreateRenderer(
21072084 const ch2 = n2 . children
21082085 if ( isArray ( ch1 ) && isArray ( ch2 ) ) {
21092086 for ( let i = 0 ; i < ch1 . length ; i ++ ) {
2110- const c1 = ch1 [ i ]
2111- const c2 = ch2 [ i ]
2112- if (
2113- isVNode ( c1 ) &&
2114- isVNode ( c2 ) &&
2115- c2 . shapeFlag & ShapeFlags . ELEMENT &&
2116- ! c2 . dynamicChildren
2117- ) {
2087+ // this is only called in the optimized path so array children are
2088+ // guaranteed to be vnodes
2089+ const c1 = ch1 [ i ] as VNode
2090+ const c2 = ( ch2 [ i ] = cloneIfMounted ( ch2 [ i ] as VNode ) )
2091+ if ( c2 . shapeFlag & ShapeFlags . ELEMENT && ! c2 . dynamicChildren ) {
21182092 if ( c2 . patchFlag <= 0 ) {
21192093 c2 . el = c1 . el
21202094 }
0 commit comments