@@ -62,9 +62,12 @@ export function diffChildren(
62
62
63
63
let newChildrenLength = renderResult . length ;
64
64
65
- newParentVNode . _nextDom = oldDom ;
66
- constructNewChildrenArray ( newParentVNode , renderResult , oldChildren ) ;
67
- oldDom = newParentVNode . _nextDom ;
65
+ oldDom = constructNewChildrenArray (
66
+ newParentVNode ,
67
+ renderResult ,
68
+ oldChildren ,
69
+ oldDom
70
+ ) ;
68
71
69
72
for ( i = 0 ; i < newChildrenLength ; i ++ ) {
70
73
childVNode = newParentVNode . _children [ i ] ;
@@ -82,7 +85,7 @@ export function diffChildren(
82
85
childVNode . _index = i ;
83
86
84
87
// Morph the old element into the new one, but don't append it to the dom yet
85
- diff (
88
+ let result = diff (
86
89
parentDom ,
87
90
childVNode ,
88
91
oldVNode ,
@@ -117,49 +120,32 @@ export function diffChildren(
117
120
oldVNode . _children === childVNode . _children
118
121
) {
119
122
oldDom = insert ( childVNode , oldDom , parentDom ) ;
120
- } else if (
121
- typeof childVNode . type == 'function' &&
122
- childVNode . _nextDom !== UNDEFINED
123
- ) {
124
- // Since Fragments or components that return Fragment like VNodes can
125
- // contain multiple DOM nodes as the same level, continue the diff from
126
- // the sibling of last DOM child of this child VNode
127
- oldDom = childVNode . _nextDom ;
123
+ } else if ( typeof childVNode . type == 'function' && result !== UNDEFINED ) {
124
+ oldDom = result ;
128
125
} else if ( newDom ) {
129
126
oldDom = newDom . nextSibling ;
130
127
}
131
128
132
- // Eagerly cleanup _nextDom. We don't need to persist the value because it
133
- // is only used by `diffChildren` to determine where to resume the diff
134
- // after diffing Components and Fragments. Once we store it the nextDOM
135
- // local var, we can clean up the property. Also prevents us hanging on to
136
- // DOM nodes that may have been unmounted.
137
- childVNode . _nextDom = UNDEFINED ;
138
-
139
129
// Unset diffing flags
140
130
childVNode . _flags &= ~ ( INSERT_VNODE | MATCHED ) ;
141
131
}
142
132
143
- // TODO: With new child diffing algo, consider alt ways to diff Fragments.
144
- // Such as dropping oldDom and moving fragments in place
145
- //
146
- // Because the newParentVNode is Fragment-like, we need to set it's
147
- // _nextDom property to the nextSibling of its last child DOM node.
148
- //
149
- // `oldDom` contains the correct value here because if the last child
150
- // is a Fragment-like, then oldDom has already been set to that child's _nextDom.
151
- // If the last child is a DOM VNode, then oldDom will be set to that DOM
152
- // node's nextSibling.
153
- newParentVNode . _nextDom = oldDom ;
154
133
newParentVNode . _dom = firstChildDom ;
134
+
135
+ return oldDom ;
155
136
}
156
137
157
138
/**
158
139
* @param {VNode } newParentVNode
159
140
* @param {ComponentChildren[] } renderResult
160
141
* @param {VNode[] } oldChildren
161
142
*/
162
- function constructNewChildrenArray ( newParentVNode , renderResult , oldChildren ) {
143
+ function constructNewChildrenArray (
144
+ newParentVNode ,
145
+ renderResult ,
146
+ oldChildren ,
147
+ oldDom
148
+ ) {
163
149
/** @type {number } */
164
150
let i ;
165
151
/** @type {VNode } */
@@ -309,14 +295,16 @@ function constructNewChildrenArray(newParentVNode, renderResult, oldChildren) {
309
295
for ( i = 0 ; i < oldChildrenLength ; i ++ ) {
310
296
oldVNode = oldChildren [ i ] ;
311
297
if ( oldVNode != null && ( oldVNode . _flags & MATCHED ) === 0 ) {
312
- if ( oldVNode . _dom == newParentVNode . _nextDom ) {
313
- newParentVNode . _nextDom = getDomSibling ( oldVNode ) ;
298
+ if ( oldVNode . _dom == oldDom ) {
299
+ oldDom = getDomSibling ( oldVNode ) ;
314
300
}
315
301
316
302
unmount ( oldVNode , oldVNode ) ;
317
303
}
318
304
}
319
305
}
306
+
307
+ return oldDom ;
320
308
}
321
309
322
310
/**
0 commit comments