Tree Component is setting parent of children to undefined on expanding a node. #14652
Labels
Status: Needs Triage
Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Describe the bug
I need a TreeNode structure where the nodes know their parents so that I can add nodes programmatically, find their path (from root), etc. Therefore, I'm populating the parent when I build the node structure. However, on expand of a node in the tree -- even just through the UI -- it is setting the value of the parent, sometimes to undefined.
Environment
Windows 10 for dev dev envirnonment, but it reproduces in Stackblitz.
Reproducer
https://stackblitz.com/edit/8tfcxu-mizzw9?file=src%2Fapp%2Fdemo%2Ftree-single-demo.html
Angular version
17.0.8
PrimeNG version
17.3.2
Build / Runtime
Angular CLI App
Language
TypeScript
Node version (for AoT issues node --version)
v20.10.0
Browser(s)
Edge: 120.0.2210.144, Chrome Version 120.0.6099.225
Steps to reproduce the behavior
The Reproducer is a copy of The PrimeNG Tree documentation single selection, with some modifications:
To reproduce: As repeated in the text of the reproducer:
Steps to reproduce:
Also, adding a breakpoint before expand, the children have a parent (key: 0)
Afterward (setting a breakpoint on collapse), they've lost their parent:
Setting a breakpoint in the MyTreeNode set parent(value), we see:
this appears to be happening in UITreeNode.ngOnInit:
Though I don't see why this.parentNode would be unset at this point, as UITreeNode's inputs should have been set:
Expected behavior
The parent of a TreeNode should not be set to undefined (or null) if it actually has a parent.
The text was updated successfully, but these errors were encountered: