Tree exceeds maximum call stack size on selection when using selectionMode "checkbox" with filter
I'm submitting a ... (check one with "x")
[X] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35
Current behavior
If you use a tree component with the selectionMode "checkbox" and the filter option, then filter the given tree for a specific value and try to select the filtered value, the tree throws an ERROR Error: Maximum call stack size exceeded error.
Expected behavior The tree component should select the filtered value.
Minimal reproduction of the problem with instructions
- Visit demo: Demo
- Search for any value in the tree. E.g. 'Untouchables'
- Select the given tree node with the label 'Untouchables'.
What is the motivation / use case for changing the behavior? I want to be able to select the filtered value.
Please tell us about your environment:
-
Angular version: 11.0.3
-
PrimeNG version: 11.2.3
-
Browser: [all]
-
Language: [all]
-
Node (for AoT issues):
node --version= 14.15.4
I'm currently experiencing the same issue. I've tried restructuring the data object to no avail. It does appear to be something to do with the checkbox as the selectionMode as pointed out by @LarsHabier. For now, the easiest option is to remove the filter option, although not ideal.
I'm facing the same issue, for now, i removed the filter option as @danorr said. We are waiting for the fix.
Also facing the same issue with single selection mode. We are waiting for the fix.
Same issue here... I have traced it back to the propagateUp() method in which the parent of the root node is the node itself yielding an infinite loop.
This seems to have been a result of the filtering code which appears to be resetting parent-child relationships...
So the problem here seems to ultimately be they node's key...
The filter method is looking up nodes by key and when they're shared (think undefined in this case) the code ends up looking for the first node with the parent of 'key'... In the undefined case it returns the FIRST node it finds which is - you guessed it the root node. So this.parentNode = root node which is problematic when you reach the root node (it references itself)
Then, when the propagateUp() gets called it traverses the nodes and parent winding up in a infinite loop...
While I still think that this is a bug it can be worked-around by assigning unique keys to each of your nodes. In your example there are many ways to accomplish this but the "easiest" is probably adding the key to the files.json file.
Gook luck!
I had same issue here. I was already providing 'key', which was the index in the initial list. It turns out that replacing this key with the label (hopefully unique) did the trick. I think it does not like to have 0 as key. Observed regression while upgrading from Angular 11 primeng 11.3.0 to Angular 12 primeng 11.4.5
Use the key property of Tree Node for the Filter and Selection on Tree.
Example: https://stackblitz.com/edit/primeng-treeselection-checkbox-bug-gtsww4?file=src%2Fassets%2Ffiles.json
Use the key property of Tree Node for the Filter and Selection on Tree.
Example: https://stackblitz.com/edit/primeng-treeselection-checkbox-bug-gtsww4?file=src%2Fassets%2Ffiles.json
It worked for me on 12/30/2021, thank you very much and happy holidays.
The question still remains if the 'key' is not unique, as was the case for my initial issues, if this will still work. In the tree that we were working with, some of the nodes could appear under multiple categories, effectively having the same key. And this was the source of the main issue we were having.
So i am still having this issue. I use a filter on the tree and use unique keys for each entry, i have even tried to do a find on the key and this only appears once so i know there are no duplicates.
do you have '0' value in your keys ?
No i am using the label of the node. On top of that the build up of the model is in a for loop so i add a incremented integer onto the end to further the uniqueness of the key.
No i am using the label of the node. On top of that the build up of the model is in a for loop so i add a incremented integer onto the end to further the uniqueness of the key.
You may have an infinite loop somewhere
Nope i have checked the console log and the model is perfectly formed. This issue only occurs when the tree is filtered.
es raro, asegurate de que los children tambien tengan su key y que no este repetido