@@ -62,9 +62,12 @@ export function diffChildren(
6262
6363 let newChildrenLength = renderResult . length ;
6464
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+ ) ;
6871
6972 for ( i = 0 ; i < newChildrenLength ; i ++ ) {
7073 childVNode = newParentVNode . _children [ i ] ;
@@ -82,7 +85,7 @@ export function diffChildren(
8285 childVNode . _index = i ;
8386
8487 // Morph the old element into the new one, but don't append it to the dom yet
85- diff (
88+ let result = diff (
8689 parentDom ,
8790 childVNode ,
8891 oldVNode ,
@@ -117,49 +120,32 @@ export function diffChildren(
117120 oldVNode . _children === childVNode . _children
118121 ) {
119122 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 ;
128125 } else if ( newDom ) {
129126 oldDom = newDom . nextSibling ;
130127 }
131128
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-
139129 // Unset diffing flags
140130 childVNode . _flags &= ~ ( INSERT_VNODE | MATCHED ) ;
141131 }
142132
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 ;
154133 newParentVNode . _dom = firstChildDom ;
134+
135+ return oldDom ;
155136}
156137
157138/**
158139 * @param {VNode } newParentVNode
159140 * @param {ComponentChildren[] } renderResult
160141 * @param {VNode[] } oldChildren
161142 */
162- function constructNewChildrenArray ( newParentVNode , renderResult , oldChildren ) {
143+ function constructNewChildrenArray (
144+ newParentVNode ,
145+ renderResult ,
146+ oldChildren ,
147+ oldDom
148+ ) {
163149 /** @type {number } */
164150 let i ;
165151 /** @type {VNode } */
@@ -309,14 +295,16 @@ function constructNewChildrenArray(newParentVNode, renderResult, oldChildren) {
309295 for ( i = 0 ; i < oldChildrenLength ; i ++ ) {
310296 oldVNode = oldChildren [ i ] ;
311297 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 ) ;
314300 }
315301
316302 unmount ( oldVNode , oldVNode ) ;
317303 }
318304 }
319305 }
306+
307+ return oldDom ;
320308}
321309
322310/**
0 commit comments