Skip to content
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

Tree Component is setting parent of children to undefined on expanding a node. #14652

Closed
mconner opened this issue Jan 29, 2024 · 2 comments
Closed
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible

Comments

@mconner
Copy link

mconner commented Jan 29, 2024

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:

  • I added a method to the nodeservice.ts to build a model TreeNode[] that sets the parent nodes.
  • I modified the template to use virtual scrolling. While the example I provide here is only 100 nodes, I need to support many more.
  • The model uses a MyTreeNode which implements a TreeNode and reports when the parent changes after initial construction of the tree.

To reproduce: As repeated in the text of the reproducer:
Steps to reproduce:

  1. Open the developer console in the Browser
  2. Expand the first node "Key: 0"
  3. You will see in the developer console that the children of Key: 0 are reporting that their parent is being set to undefined
  4. Also, if you un-expand and then expand again, all at once (i.e.: after the expand) the nodes are first properly set, and then set to undefined again.

Also, adding a breakpoint before expand, the children have a parent (key: 0)

image

Afterward (setting a breakpoint on collapse), they've lost their parent:

image

Setting a breakpoint in the MyTreeNode set parent(value), we see:

set parent (main.js:400)
ngOnInit (vendor.js:220767)
callHookInternal (vendor.js:69487)

this appears to be happening in UITreeNode.ngOnInit:

  ngOnInit() {
    this.node.parent = this.parentNode;
    if (this.parentNode) {
      this.setAllNodesTabIndexes();
      this.tree.syncNodeOption(this.node, this.tree.value, 'parent', this.tree.getNodeWithKey(this.parentNode.key, this.tree.value));
    }
  }

Though I don't see why this.parentNode would be unset at this point, as UITreeNode's inputs should have been set:

ngOnInit() Initialize the directive or component after Angular first displays the data-bound properties and sets the directive or component's input properties.

Expected behavior

The parent of a TreeNode should not be set to undefined (or null) if it actually has a parent.

@mconner mconner added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jan 29, 2024
@zachsteffens
Copy link

I'm having the same issue. Any timeline for resolution?

@mehmetcetin01140
Copy link
Contributor

Hi,

So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you open a new issue so we can include it in our roadmap?

Thanks a lot for your understanding!
Best Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Projects
None yet
Development

No branches or pull requests

3 participants