primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Tree exceeds maximum call stack size on selection when using selectionMode "checkbox" with filter

Open LarsHabier opened this issue 5 years ago • 15 comments

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

  1. Visit demo: Demo
  2. Search for any value in the tree. E.g. 'Untouchables'
  3. 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

LarsHabier avatar Feb 24 '21 08:02 LarsHabier

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.

danorr avatar Mar 09 '21 22:03 danorr

I'm facing the same issue, for now, i removed the filter option as @danorr said. We are waiting for the fix.

snkdarian avatar Mar 17 '21 08:03 snkdarian

Also facing the same issue with single selection mode. We are waiting for the fix.

naory159 avatar Mar 23 '21 15:03 naory159

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...

wcroteau avatar Apr 19 '21 17:04 wcroteau

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!

wcroteau avatar Apr 19 '21 19:04 wcroteau

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

wokier avatar Sep 28 '21 16:09 wokier

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

yigitfindikli avatar Nov 18 '21 13:11 yigitfindikli

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.

ArtToledo avatar Dec 30 '21 17:12 ArtToledo

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.

danorr avatar Dec 31 '21 03:12 danorr

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.

DazedDragon avatar Mar 16 '22 10:03 DazedDragon

do you have '0' value in your keys ?

wokier avatar Mar 16 '22 11:03 wokier

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.

DazedDragon avatar Mar 16 '22 11:03 DazedDragon

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

wokier avatar Mar 16 '22 11:03 wokier

Nope i have checked the console log and the model is perfectly formed. This issue only occurs when the tree is filtered.

DazedDragon avatar Mar 16 '22 11:03 DazedDragon

es raro, asegurate de que los children tambien tengan su key y que no este repetido

chrisolivaresdev avatar Jul 11 '22 20:07 chrisolivaresdev