From 8e5eac568910e916d74b0322cc02ba01c6df7ff1 Mon Sep 17 00:00:00 2001 From: Andre Wiggins <459878+andrewiggins@users.noreply.github.com> Date: Fri, 27 Oct 2023 17:49:32 -0700 Subject: [PATCH] Use copied VNode as newVNode instead of oldVNode when rerendering (#4171) --- src/component.js | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/component.js b/src/component.js index 4111f108d6..73c5afd2e4 100644 --- a/src/component.js +++ b/src/component.js @@ -120,39 +120,35 @@ export function getDomSibling(vnode, childIndex) { * @param {Component} component The component to rerender */ function renderComponent(component) { - let vnode = component._vnode, - oldDom = vnode._dom, + let oldVNode = component._vnode, + oldDom = oldVNode._dom, parentDom = component._parentDom; if (parentDom) { let commitQueue = [], refQueue = []; - const oldVNode = assign({}, vnode); - oldVNode._original = vnode._original + 1; - if (oldVNode._children) { - oldVNode._children.forEach(child => { - if (child) child._parent = oldVNode; - }); - } + const newVNode = assign({}, oldVNode); + newVNode._original = oldVNode._original + 1; diff( parentDom, - vnode, + newVNode, oldVNode, component._globalContext, parentDom.ownerSVGElement !== undefined, - vnode._hydrating != null ? [oldDom] : null, + oldVNode._hydrating != null ? [oldDom] : null, commitQueue, - oldDom == null ? getDomSibling(vnode) : oldDom, - vnode._hydrating, + oldDom == null ? getDomSibling(oldVNode) : oldDom, + oldVNode._hydrating, refQueue ); - commitRoot(commitQueue, vnode, refQueue); + newVNode._parent._children[newVNode._index] = newVNode; + commitRoot(commitQueue, newVNode, refQueue); - if (vnode._dom != oldDom) { - updateParentDomPointers(vnode); + if (newVNode._dom != oldDom) { + updateParentDomPointers(newVNode); } } }