@@ -10,7 +10,8 @@ import {
10
10
isSameVNodeType ,
11
11
Static ,
12
12
VNodeNormalizedRef ,
13
- VNodeHook
13
+ VNodeHook ,
14
+ isVNode
14
15
} from './vnode'
15
16
import {
16
17
ComponentInternalInstance ,
@@ -33,7 +34,8 @@ import {
33
34
ShapeFlags ,
34
35
NOOP ,
35
36
hasOwn ,
36
- invokeArrayFns
37
+ invokeArrayFns ,
38
+ isArray
37
39
} from '@vue/shared'
38
40
import {
39
41
queueJob ,
@@ -769,6 +771,9 @@ function baseCreateRenderer(
769
771
parentSuspense ,
770
772
areChildrenSVG
771
773
)
774
+ if ( __DEV__ && parentComponent && parentComponent . type . __hmrId ) {
775
+ traverseStaticChildren ( n1 , n2 )
776
+ }
772
777
} else if ( ! optimized ) {
773
778
// full diff
774
779
patchChildren (
@@ -933,6 +938,9 @@ function baseCreateRenderer(
933
938
parentSuspense ,
934
939
isSVG
935
940
)
941
+ if ( __DEV__ && parentComponent && parentComponent . type . __hmrId ) {
942
+ traverseStaticChildren ( n1 , n2 )
943
+ }
936
944
} else {
937
945
// keyed / unkeyed, or manual fragments.
938
946
// for keyed & unkeyed, since they are compiler generated from v-for,
@@ -1944,6 +1952,31 @@ function baseCreateRenderer(
1944
1952
}
1945
1953
}
1946
1954
1955
+ /**
1956
+ * #1156
1957
+ * When a component is HMR-enabled, we need to make sure that all static nodes
1958
+ * inside a block also inherit the DOM element from the previous tree so that
1959
+ * HMR updates (which are full updates) can retrieve the element for patching.
1960
+ *
1961
+ * Dev only.
1962
+ */
1963
+ const traverseStaticChildren = ( n1 : VNode , n2 : VNode ) => {
1964
+ const ch1 = n1 . children
1965
+ const ch2 = n2 . children
1966
+ if ( isArray ( ch1 ) && isArray ( ch2 ) ) {
1967
+ for ( let i = 0 ; i < ch1 . length ; i ++ ) {
1968
+ const c1 = ch1 [ i ]
1969
+ const c2 = ch2 [ i ]
1970
+ if ( isVNode ( c1 ) && isVNode ( c2 ) && ! c2 . dynamicChildren ) {
1971
+ if ( c2 . patchFlag <= 0 ) {
1972
+ c2 . el = c1 . el
1973
+ }
1974
+ traverseStaticChildren ( c1 , c2 )
1975
+ }
1976
+ }
1977
+ }
1978
+ }
1979
+
1947
1980
const render : RootRenderFunction = ( vnode , container ) => {
1948
1981
if ( vnode == null ) {
1949
1982
if ( container . _vnode ) {
0 commit comments