From e8169f8be2ef0806278a7b38fbdc1d1650574dc8 Mon Sep 17 00:00:00 2001 From: Suresh Kumar Gangumalla Date: Wed, 17 Apr 2024 12:26:06 +0530 Subject: [PATCH 1/6] Destroy hook in children components not invoked While navigating away previous router view will get removed, as part of it invoking destroy method on previousView but before that making all children elements/Components to null leads to failure of setting state of children component to destroy so respecitve destroy hook in that component won't execute Signed-off-by: Suresh Kumar Gangumalla --- src/router/router.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/router/router.js b/src/router/router.js index dfc3dd23..a9f8d590 100644 --- a/src/router/router.js +++ b/src/router/router.js @@ -257,7 +257,7 @@ const removeView = async (route, view, transition) => { for (let i = 0; i < view[symbols.children].length; i++) { // if (view[symbols.children][i] && view[symbols.children][i].destroy) { // view[symbols.children][i].destroy() - view[symbols.children][i] = null + // view[symbols.children][i] = null // } } view.destroy() From 035461a3f190d237b54f46a289365f0f2871ba4a Mon Sep 17 00:00:00 2001 From: Suresh Kumar Gangumalla Date: Wed, 17 Apr 2024 14:52:28 +0530 Subject: [PATCH 2/6] Removed looping over children components Signed-off-by: Suresh Kumar Gangumalla --- src/router/router.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/router/router.js b/src/router/router.js index a9f8d590..e097417c 100644 --- a/src/router/router.js +++ b/src/router/router.js @@ -253,13 +253,6 @@ const removeView = async (route, view, transition) => { if (route.options && route.options.keepAlive === true) { cacheMap.set(route, { view: view, focus: previousFocus }) } else { - // remove and cleanup - for (let i = 0; i < view[symbols.children].length; i++) { - // if (view[symbols.children][i] && view[symbols.children][i].destroy) { - // view[symbols.children][i].destroy() - // view[symbols.children][i] = null - // } - } view.destroy() view = null } From 4fc928caf399e7753f75b01046aea3a637f95cc2 Mon Sep 17 00:00:00 2001 From: Suresh Kumar Gangumalla Date: Wed, 17 Apr 2024 18:34:01 +0530 Subject: [PATCH 3/6] Destroying components rendered thorugh for-loop Handled destroying components that are rendered in a loop Signed-off-by: Suresh Kumar Gangumalla --- src/lib/setup/base.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib/setup/base.js b/src/lib/setup/base.js index ff1c49c4..31134fde 100644 --- a/src/lib/setup/base.js +++ b/src/lib/setup/base.js @@ -274,6 +274,13 @@ const deleteChildren = function (children) { if (!children[i]) return if (Array.isArray(children[i])) { deleteChildren(children[i]) + } else if (Object.getPrototypeOf(children[i]) === Object.prototype) { + Object.keys(children[i]).forEach((k) => { + if (children[i][k].destroy) { + children[i][k].destroy() + children[i][k] = null + } + }) } else if (children[i].destroy) { children[i].destroy() } From e1ad4b337c98b3bcbfa3cb128203aa36db6324b8 Mon Sep 17 00:00:00 2001 From: Suresh Kumar Gangumalla Date: Wed, 17 Apr 2024 18:39:18 +0530 Subject: [PATCH 4/6] Make sure to set all children to null Signed-off-by: Suresh Kumar Gangumalla --- src/lib/setup/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/setup/base.js b/src/lib/setup/base.js index 31134fde..92fa11dc 100644 --- a/src/lib/setup/base.js +++ b/src/lib/setup/base.js @@ -278,8 +278,8 @@ const deleteChildren = function (children) { Object.keys(children[i]).forEach((k) => { if (children[i][k].destroy) { children[i][k].destroy() - children[i][k] = null } + children[i][k] = null }) } else if (children[i].destroy) { children[i].destroy() From c884fabb716c1d0602f30ea3ae5325d9feccb974 Mon Sep 17 00:00:00 2001 From: Michiel van der Geest Date: Wed, 17 Apr 2024 22:59:26 +0200 Subject: [PATCH 5/6] Updated delete method to recursively call itself when dealing with an object of children (created by a for loop). --- src/lib/setup/base.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/lib/setup/base.js b/src/lib/setup/base.js index 92fa11dc..6a85cbf8 100644 --- a/src/lib/setup/base.js +++ b/src/lib/setup/base.js @@ -272,18 +272,19 @@ export default (component, name) => { const deleteChildren = function (children) { for (let i = 0; i < children.length; i++) { if (!children[i]) return - if (Array.isArray(children[i])) { - deleteChildren(children[i]) - } else if (Object.getPrototypeOf(children[i]) === Object.prototype) { - Object.keys(children[i]).forEach((k) => { - if (children[i][k].destroy) { - children[i][k].destroy() - } - children[i][k] = null - }) - } else if (children[i].destroy) { + // call destroy when method is available on child + if (children[i].destroy && typeof children[i].destroy === 'function') { children[i].destroy() } + // recursively call deleteChildren when it's an object of items (happens when using a forloop construct) + else if (Object.getPrototypeOf(children[i]) === Object.prototype) { + deleteChildren(Object.values(children[i])) + } + // todo: this case may not be needed anymore + else if (Array.isArray(children[i])) { + deleteChildren(children[i]) + } + children[i] = null } From c5ccbb6170c705cc5a489ff1a54fb9feb435caf5 Mon Sep 17 00:00:00 2001 From: Suresh Kumar Gangumalla Date: Thu, 18 Apr 2024 11:06:26 +0530 Subject: [PATCH 6/6] Verified and removed recursive deleteChildren Signed-off-by: Suresh Kumar Gangumalla --- src/lib/setup/base.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/lib/setup/base.js b/src/lib/setup/base.js index 6a85cbf8..d4dab80e 100644 --- a/src/lib/setup/base.js +++ b/src/lib/setup/base.js @@ -280,10 +280,6 @@ const deleteChildren = function (children) { else if (Object.getPrototypeOf(children[i]) === Object.prototype) { deleteChildren(Object.values(children[i])) } - // todo: this case may not be needed anymore - else if (Array.isArray(children[i])) { - deleteChildren(children[i]) - } children[i] = null }