perf(ivy): don't relink the whole tree when `TNode` exists (#30511)

PR Close #30511
This commit is contained in:
Olivier Combe 2019-05-16 14:42:58 +02:00 committed by Jason Aden
parent 79903b1842
commit f2ae452f01
1 changed files with 9 additions and 11 deletions

View File

@ -271,18 +271,16 @@ export function createNodeAtIndex(
const tParentNode = parentInSameView ? parent as TElementNode | TContainerNode : null; const tParentNode = parentInSameView ? parent as TElementNode | TContainerNode : null;
tNode = tView.data[adjustedIndex] = createTNode(tParentNode, type, adjustedIndex, name, attrs); tNode = tView.data[adjustedIndex] = createTNode(tParentNode, type, adjustedIndex, name, attrs);
}
// Now link ourselves into the tree. // Now link ourselves into the tree.
// We need this even if tNode exists, otherwise we might end up pointing to unexisting tNodes when if (previousOrParentTNode) {
// we use i18n (especially with ICU expressions that update the DOM during the update phase). if (isParent && previousOrParentTNode.child == null &&
if (previousOrParentTNode) { (tNode.parent !== null || previousOrParentTNode.type === TNodeType.View)) {
if (isParent && previousOrParentTNode.child == null && // We are in the same view, which means we are adding content node to the parent view.
(tNode.parent !== null || previousOrParentTNode.type === TNodeType.View)) { previousOrParentTNode.child = tNode;
// We are in the same view, which means we are adding content node to the parent view. } else if (!isParent) {
previousOrParentTNode.child = tNode; previousOrParentTNode.next = tNode;
} else if (!isParent) { }
previousOrParentTNode.next = tNode;
} }
} }