From 63e70fd3f1eae634f7160d68a3070369a90249d7 Mon Sep 17 00:00:00 2001 From: jdecroock Date: Thu, 18 May 2023 14:23:02 +0200 Subject: [PATCH] simplify more checks --- src/diff/children.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/diff/children.js b/src/diff/children.js index 5bedfe0691..47cbd75b1a 100644 --- a/src/diff/children.js +++ b/src/diff/children.js @@ -122,15 +122,11 @@ export function diffChildren( if (matchingIndex === -1) { oldVNode = EMPTY_OBJ; } else { - oldVNode = oldChildren[matchingIndex]; + oldVNode = oldChildren[matchingIndex] || EMPTY_OBJ; oldChildren[matchingIndex] = undefined; remainingOldChildren--; } - oldVNode = oldVNode || EMPTY_OBJ; - let isMounting = - isHydrating || oldVNode === EMPTY_OBJ || oldVNode._original === null; - // Morph the old element into the new one, but don't append it to the dom yet diff( parentDom, @@ -157,12 +153,13 @@ export function diffChildren( firstChildDom = newDom; } + let isMounting = oldVNode === EMPTY_OBJ || oldVNode._original === null; let hasMatchingIndex = !isMounting && matchingIndex === skewedIndex; if (isMounting) { if (matchingIndex == -1) { skew--; } - } else if (!hasMatchingIndex) { + } else if (matchingIndex !== skewedIndex) { if (matchingIndex === skewedIndex + 1) { skew++; hasMatchingIndex = true; @@ -186,11 +183,11 @@ export function diffChildren( } skewedIndex = i + skew; - if (matchingIndex == i && !isMounting) { - hasMatchingIndex = true; - } + hasMatchingIndex = + hasMatchingIndex || (matchingIndex == i && !isMounting); if ( + !isHydrating && !isMounting && typeof childVNode.type == 'function' && (matchingIndex !== skewedIndex ||