-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unpredictable results when scope.$id is less than the length of your expandedNodesMap in the treeTransclude directive #210
Comments
|
Now, after the tree transclude directive runs perhaps my expandedNodesMap looks as follows: so now, based on the code, I can see that the scope $ids of my nodes are 8, 12, & 15. No problem there. Now imagine my original expandedNodesMap had size 20 with keys 1-20 pointing to nodes 1-20 respectively. What would happen in the treeTransclude directive, if node 1 had a generated scope $id of 8? Now instead of marking key 1 undefined and creating a new item with key of 8, you would instead be overwriting the existing node 8 with node 1. Does that make sense? So key1 would be marked undefined but instead of creating a new node 1 with key 8 you would be overwriting the existing node 8 with node 1. Does that explain it any better? |
I've experienced (probably) the same behaviour with big trees (>500 nodes) as @mjohnson1122 describes. When the whole tree is expanded, by inserting every node in the expanded-nodes array, the result isn't as expected. Sometimes the whole tree is expanded and sometimes only parts of it. Sometimes the root node level isn't expanded at all (but the child nodes are, if we expand the root node by clicking it). To reproduce this issue I've created a plunkr with trees of various size: You should see the effect in the tree with size [1,5,10,15]. The first expand result differs from further ones. Try clicking the buttons "Expand nodes" and "Collapse nodes" multiple times. Hopefully this will help to debug the issue. |
Yes, that's it exactly. We experienced the same behavior. Our trees, which should have been fully expanded by default, weren't displaying as such. Some nodes would be expanded, some wouldn't. And trying to manually expand or collapse particular nodes, would also result in some weird behavior. In one example, trying to expand a node that should have already been expanded resulted in a completely different set of nodes expanding and then collapsing before the node I clicked on finally expanded. Other times, trying to expand a node, resulted in nothing happening at all. All of this stems from when a scope.$id for a particular node is the same as an existing key in the expandedNodesMap. When the expandedNodesMap is first populated, the key to each node is the index of a for loop. So when the map is modified to use the scope.$id as the key, if the scope.$id matches one of the original for loop indices, you will encounter these types of problems. |
Actually, in looking at the pull requests out there, it looks as if #124 would address this very issue. |
@kaape, I have checked your plunkr. The issue there is caused by the data having multiple nodes with the same index and the quality function comparing nodes only based on index. In the second tree, the nodes
and
have the same index numbers. |
@yoavaa Sorry, my bad. I've updated the plunkr to prevent duplicate node indexes. Although the behaviour is slightly different, the issue is still occurring. Not all nodes are expanded on first try (at least for the third tree). |
(cannot reproduce in tests, but can reproduce in https://plnkr.co/edit/rWgobIGvTF9rnzyI02Mu?p=preview)
try now with the latest pushed version of the library. I cannot reproduce in tests but I think I have implemented a fix that will solve this issue. Works for me in plunkr |
Yes, this fixes the problem. Thanks, |
Guys, could you publish this fix to |
@yoavaa ping |
done |
Sorry, but can't see it in npm - last version is still |
now should work. On Wed, Jul 6, 2016 at 2:39 PM Yuriy Grunin [email protected]
|
So I have a rather large tree (thousands of nodes) which defaults to expanding all branches. My expandedNodesMap has over 500 nodes in it. If I'm using this relatively early in the lifetime of my app, the scope.$id in the treeTransclude directive is less than the length of my expandedNodesMap.
Thus, when I get to the following code in that directive:
it completely overwrites an existing node in the map because scope.$id is < length of the map. This causes some very unpredictable results.
The text was updated successfully, but these errors were encountered: