From 44f17a126baea0cf116283aee2d8391d9c8998d7 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Sun, 24 Jan 2021 14:30:58 -0500 Subject: [PATCH] Size optimizations for excessDomChildren --- src/diff/index.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/diff/index.js b/src/diff/index.js index da767fff04..63b59ee8c6 100644 --- a/src/diff/index.js +++ b/src/diff/index.js @@ -300,30 +300,25 @@ function diffElementNodes( commitQueue, isHydrating ) { - let i; let oldProps = oldVNode.props; let newProps = newVNode.props; let nodeType = newVNode.type; + let i = 0; // Tracks entering and exiting SVG namespace when descending through the tree. if (nodeType === 'svg') isSvg = true; if (excessDomChildren != null) { - for (i = 0; i < excessDomChildren.length; i++) { + for (; i < excessDomChildren.length; i++) { const child = excessDomChildren[i]; // if newVNode matches an element in excessDomChildren or the `dom` // argument matches an element in excessDomChildren, remove it from // excessDomChildren so it isn't later removed in diffChildren - // - // Note: This takes advantage of Text nodes having `.localName=undefined`, - // which is loosely equal to Text VNodes' `.type=null`. Elements use string equality. if ( - child != null && - ((nodeType === null - ? child.nodeType === 3 - : child.localName === nodeType) || - dom == child) + child && + (child === dom || + (nodeType ? child.localName == nodeType : child.nodeType == 3)) ) { dom = child; excessDomChildren[i] = null; @@ -364,9 +359,9 @@ function diffElementNodes( dom.data = newProps; } } else { - if (excessDomChildren != null) { - excessDomChildren = EMPTY_ARR.slice.call(dom.childNodes); - } + // If excessDomChildren was not null, repopulate it with the current element's children: + excessDomChildren = + excessDomChildren && EMPTY_ARR.slice.call(dom.childNodes); oldProps = oldVNode.props || EMPTY_OBJ;