debugger icon indicating copy to clipboard operation
debugger copied to clipboard

[sources] source tree loses focuses when new items are added

Open jasonLaster opened this issue 8 years ago • 8 comments

STR:

  1. go to https://www.cnn.com/
  2. reload
  3. click on items in the source tree

ER: it stays focused AR: it loses its focus

jasonLaster avatar Aug 22 '18 15:08 jasonLaster

so this looks related...

diff --git a/src/utils/sources-tree/updateTree.js b/src/utils/sources-tree/updateTree.js
index 14a1036..040e8a6 100644
--- a/src/utils/sources-tree/updateTree.js
+++ b/src/utils/sources-tree/updateTree.js
@@ -51,7 +51,7 @@ export function updateTree({
   return {
     uncollapsedTree,
     sourceTree: newSourceTree,
-    parentMap: createParentMap(newSourceTree),
-    focusedItem: null
+    parentMap: createParentMap(newSourceTree)
+    // focusedItem: null
   };
 }

jasonLaster avatar Aug 22 '18 21:08 jasonLaster

I'm going to start looking into this one after work :)

WenInCode avatar Sep 07 '18 20:09 WenInCode

/claim

WenInCode avatar Sep 07 '18 20:09 WenInCode

Thanks for claiming the issue! :wave:

Here are some links for getting setup, contributing, and developing. We're always happy to answer questions in slack! If you become busy, feel free to /unclaim it.

:fox_face: Debugger team!

claim avatar Sep 07 '18 20:09 claim

I just wanted to give an update on where I am at with this. I didn't get a chance to do much work on it last week, but I've been a bit more active this week.

As @jasonLaster pointed out the issue is that when the tree is updated we return the state with focusedItem set to null. However, if we were to remove that setting altogether, and leave focusedItem as it were before updating the tree it would still lose focus. That's because when the tree is adding nodes, it checks if the current node is focused by doing a focused === item comparison. I'm no expert on coercion, but I think that equation doesn't return true with objects unless they are a reference to the same object.

If I were to change the check to just compare paths, and not the entire object, you could just leave focusedItem as unchanged in the state. This seems to perform fine in the case where new sources are being loaded on the same page. However, I don't think it would make sense if you were loading a new page and the previous focusedItem would no longer be in the tree.

This is leading me towards keeping the equality check the same, but searching for the focuseditem in the new source tree after or during the updateTree call. I think I would have to use something similar to traverseTree to search for the node given the path. Of course, without creating a new node.

Anywho, just wanted to give an update on my thoughts. This has been a great opportunity for learning how the SourcesTree, ManagedTree, Tree, and TreeNode components work.

WenInCode avatar Sep 19 '18 15:09 WenInCode

@WenInCode i think you've got a good idea of what's going on.

CC @AnshulMalik curious what you think. Please go deeper than I did and give some suggestions on how you'd approach this :)

jasonLaster avatar Sep 19 '18 23:09 jasonLaster

Hey @WenInCode you are knocking at the right door. :)

The issue is I think in collapseTree.js. So when new sources arrive, we take the previous uncollapsed tree and create a new collapsed one. In the process we are not using the existing nodes, rather we create new ones. That's why the === check on focusedItem reference does't return true.

I have two workarounds in mind,

  1. We can reuse the nodes from previous collapsed tree.
  2. You have mentioned it in your comment, that use path of currently focused item, to find the new node that we should focus. We can directly jump directories if we split the path of currently focused item, so probably won't need to traverse the whole tree.

Let me know what you think @WenInCode @jasonLaster

AnshulMalik avatar Sep 20 '18 02:09 AnshulMalik

@AnshulMalik Thanks for the information 😄. I have some good progress on the 2nd option. I'm hoping to have a PR up soon.

WenInCode avatar Sep 20 '18 18:09 WenInCode