From c00b328eafb2e8f891a25e4b3502aa937b674b2d Mon Sep 17 00:00:00 2001 From: msaelices Date: Wed, 1 Aug 2018 04:03:14 +0200 Subject: [PATCH 1/4] chore: more useful tracing information related to the VDom operations --- platform/nativescript/runtime/node-ops.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/nativescript/runtime/node-ops.js b/platform/nativescript/runtime/node-ops.js index b993017d..0d18b0a0 100644 --- a/platform/nativescript/runtime/node-ops.js +++ b/platform/nativescript/runtime/node-ops.js @@ -41,19 +41,19 @@ export function appendChild(node, child) { } export function parentNode(node) { - trace(`ParentNode(${node})`) + trace(`ParentNode(${node}) -> ${node.parentNode}`) return node.parentNode } export function nextSibling(node) { - trace(`NextSibling(${node})`) + trace(`NextSibling(${node}) -> ${node.nextSibling}`) return node.nextSibling } export function tagName(elementNode) { - trace(`TagName(${elementNode})`) + trace(`TagName(${elementNode}) -> ${elementNode.tagName}`) return elementNode.tagName } From eaef6c6116c53558b8cab7438ce6154999bd0bb4 Mon Sep 17 00:00:00 2001 From: msaelices Date: Wed, 1 Aug 2018 04:05:53 +0200 Subject: [PATCH 2/4] fix: reset node next sibling when removing it to be able to add the components again. Fix #220 --- platform/nativescript/renderer/ViewNode.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/platform/nativescript/renderer/ViewNode.js b/platform/nativescript/renderer/ViewNode.js index 9d8f6534..a8c84fdf 100644 --- a/platform/nativescript/renderer/ViewNode.js +++ b/platform/nativescript/renderer/ViewNode.js @@ -246,6 +246,11 @@ export default class ViewNode { childNode.nextSibling.prevSibling = childNode.prevSibling } + // reset the nextSibling. If not, a keep-alived component will + // still have a filled nextSibling attribute so vue will not + // insert the node again to the parent. See #220 + childNode.nextSibling = null + this.childNodes = this.childNodes.filter(node => node !== childNode) viewUtil.removeChild(this, childNode) From ba420bf30be761978265efd9dcf787e44d6f36ca Mon Sep 17 00:00:00 2001 From: msaelices Date: Wed, 1 Aug 2018 04:11:20 +0200 Subject: [PATCH 3/4] test: cleaner sample app which test the #220 issue --- samples/app/220.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/samples/app/220.js b/samples/app/220.js index d3771a92..282d07d3 100644 --- a/samples/app/220.js +++ b/samples/app/220.js @@ -5,14 +5,12 @@ Vue.config.silent = false const CompButton = { template: ` - + `, name: 'CompButton', - props: ['label'], - data() { - return { - counter: 0 - } + props: ['label', 'counter'], + destroyed() { + console.log('Component destroyed. This should not happen') } } @@ -27,8 +25,8 @@ new Vue({ - - + + From d69c1ce7b1903a219e30de74490d272a5da76ad4 Mon Sep 17 00:00:00 2001 From: rigor789 Date: Wed, 1 Aug 2018 15:09:08 +0200 Subject: [PATCH 4/4] fix: reset the prevSibling of the removed childNode --- __tests__/renderer/ViewNode.test.js | 2 ++ platform/nativescript/renderer/ViewNode.js | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/__tests__/renderer/ViewNode.test.js b/__tests__/renderer/ViewNode.test.js index 4c55255f..2baa96f8 100644 --- a/__tests__/renderer/ViewNode.test.js +++ b/__tests__/renderer/ViewNode.test.js @@ -241,6 +241,8 @@ describe('ViewNode', () => { expect(prevChildNode.nextSibling).toEqual(nextChildNode) expect(nextChildNode.prevSibling).toEqual(prevChildNode) expect(childNode.parentNode).toBeNull() + expect(childNode.prevSibling).toBeNull() + expect(childNode.nextSibling).toBeNull() }) test('nativeView can be set once', () => { diff --git a/platform/nativescript/renderer/ViewNode.js b/platform/nativescript/renderer/ViewNode.js index a8c84fdf..d480dec8 100644 --- a/platform/nativescript/renderer/ViewNode.js +++ b/platform/nativescript/renderer/ViewNode.js @@ -246,9 +246,10 @@ export default class ViewNode { childNode.nextSibling.prevSibling = childNode.prevSibling } - // reset the nextSibling. If not, a keep-alived component will + // reset the prevSibling and nextSibling. If not, a keep-alived component will // still have a filled nextSibling attribute so vue will not // insert the node again to the parent. See #220 + childNode.prevSibling = null childNode.nextSibling = null this.childNodes = this.childNodes.filter(node => node !== childNode)