From 432ff444a16e98fea34994c971af25425b02215e Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Fri, 23 Jun 2023 15:44:19 +0200 Subject: [PATCH] [FIX] devtools: fix incorrect path resolution for subscriptions Since we now omit some observed objects when listing subscriptions, the index of the subscription is no longer the index of the raw subscription. This causes issue with the resolution of object paths when they are inside a subscription. This commit fixes that by adding the index to the raw subscription. We also need to adapt the code that traverses the old tree, since the index of the subscription in the component is no longer the same as the index of the subscription "child" in the object tree. --- .../page_scripts/owl_devtools_global_hook.js | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/devtools/src/page_scripts/owl_devtools_global_hook.js b/tools/devtools/src/page_scripts/owl_devtools_global_hook.js index 519f3b24..3c96a28c 100644 --- a/tools/devtools/src/page_scripts/owl_devtools_global_hook.js +++ b/tools/devtools/src/page_scripts/owl_devtools_global_hook.js @@ -847,7 +847,10 @@ let path = completePath.slice(objPathIndex); let obj; if (objType === "subscription") { - obj = oldTree.subscriptions.children[path[1].value].target; + const subscriptionPath = completePath.slice(0, objPathIndex + 3); + obj = oldTree.subscriptions.children.find( + (child) => JSON.stringify(child.target.path) === JSON.stringify(subscriptionPath) + ).target; path = path.slice(3); } else { // Everything here is in component if it is not an app so remove this key of the path in the former case @@ -1265,7 +1268,7 @@ toggled: oldTree ? oldTree.subscriptions.toggled : true, children: [], }; - rawSubscriptions.forEach((rawSubscription, index) => { + rawSubscriptions.forEach((rawSubscription) => { let subscription = { target: { name: this.targetName(rawSubscription.target, node), @@ -1279,7 +1282,7 @@ path: [ ...path, { type: "item", value: "subscriptions" }, - { type: "item", value: index }, + { type: "item", value: rawSubscription.index }, { type: "item", value: "target" }, ], toggled: false, @@ -1288,8 +1291,8 @@ }; if ( oldTree && - oldTree.subscriptions.children[index] && - oldTree.subscriptions.children[index].target.toggled + oldTree.subscriptions.children[rawSubscription.index] && + oldTree.subscriptions.children[rawSubscription.index].target.toggled ) { subscription.target.toggled = true; } @@ -1682,9 +1685,12 @@ * subscriptions of the node */ topLevelSubscriptions(node) { - const subscriptions = node.subscriptions; + const subscriptions = node.subscriptions.map((s, index) => ({ ...s, index })); + const topLevelValues = new Set(Object.values(node.component).map((o) => this.toRaw(o))); const toOmit = new Set( - subscriptions.flatMap(({ keys, target }) => keys.map((k) => this.toRaw(target[k]))) + subscriptions + .flatMap(({ keys, target }) => keys.map((k) => this.toRaw(target[k]))) + .filter((obj) => !topLevelValues.has(obj)) ); return subscriptions.filter(({ target }) => !toOmit.has(target)); }