From 243348b500f51c05e3863e4d39e60a6b7623bbcc Mon Sep 17 00:00:00 2001 From: Ben Delaney Date: Thu, 4 Mar 2021 23:02:45 +1100 Subject: [PATCH 1/3] chore: remove unnecessary check from appendChild --- platform/nativescript/renderer/ViewNode.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/platform/nativescript/renderer/ViewNode.js b/platform/nativescript/renderer/ViewNode.js index c5eddb98..f76848bb 100644 --- a/platform/nativescript/renderer/ViewNode.js +++ b/platform/nativescript/renderer/ViewNode.js @@ -220,16 +220,7 @@ export default class ViewNode { ) } - if (childNode.parentNode === this) { - // we don't need to throw an error here, because it is a valid case - // for example when switching the order of elements in the tree - // fixes #127 - see for more details - // fixes #240 - // throw new Error(`Can't append child, because it is already a child.`) - } - childNode.parentNode = this - if (this.lastChild) { childNode.prevSibling = this.lastChild this.lastChild.nextSibling = childNode From 233a8156a9ed2ab1d7a1b0340316d8b6082bc1d4 Mon Sep 17 00:00:00 2001 From: Ben Delaney Date: Thu, 4 Mar 2021 23:04:10 +1100 Subject: [PATCH 2/3] fix: remove node before appending if already a child --- platform/nativescript/renderer/ViewNode.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/platform/nativescript/renderer/ViewNode.js b/platform/nativescript/renderer/ViewNode.js index f76848bb..57819994 100644 --- a/platform/nativescript/renderer/ViewNode.js +++ b/platform/nativescript/renderer/ViewNode.js @@ -165,13 +165,11 @@ export default class ViewNode { throw new Error(`Can't insert child.`) } - // in some rare cases insertBefore is called with a null referenceNode - // this makes sure that it get's appended as the last child - if (!referenceNode) { - return this.appendChild(childNode) - } - - if (referenceNode.parentNode && referenceNode.parentNode !== this) { + if ( + referenceNode && + referenceNode.parentNode && + referenceNode.parentNode !== this + ) { throw new Error( `Can't insert child, because the reference node has a different parent.` ) @@ -197,6 +195,12 @@ export default class ViewNode { // throw new Error(`Can't insert child, because it is already a child.`) } + // in some rare cases insertBefore is called with a null referenceNode + // this makes sure that it get's appended as the last child + if (!referenceNode) { + return this.appendChild(childNode) + } + let index = this.childNodes.indexOf(referenceNode) childNode.parentNode = this From 1c4a00e8583c6d0a76dc828eb86c97f5bcd4c2b5 Mon Sep 17 00:00:00 2001 From: Ben Delaney Date: Thu, 4 Mar 2021 23:11:49 +1100 Subject: [PATCH 3/3] fix: set nextSibling of prevSibling upon insertion --- platform/nativescript/renderer/ViewNode.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/platform/nativescript/renderer/ViewNode.js b/platform/nativescript/renderer/ViewNode.js index 57819994..571fe523 100644 --- a/platform/nativescript/renderer/ViewNode.js +++ b/platform/nativescript/renderer/ViewNode.js @@ -204,6 +204,8 @@ export default class ViewNode { let index = this.childNodes.indexOf(referenceNode) childNode.parentNode = this + if (childNode.prevSibling) childNode.prevSibling.nextSibling = childNode + childNode.nextSibling = referenceNode childNode.prevSibling = this.childNodes[index - 1]