bug(mat-tree): childrenAccessor is not lazily evaluated and leaf nodes are not filtered out before calling the childrenAccessor
- Langage dominant
- TypeScript
- Étoiles
- 25k
- Forks
- 6.8k
- Merge moyen
- 1 j 8 h
- PR mergées (30 j)
- 91
Description
### Is this a regression?
- [ ] Yes, this behavior used to work in the previous version
### The previous version in which this bug was not present was
_No response_
### Description
`childrenAccessor` should only be called when expanding a node.
In the current state, workarounds are needed to support a mat-tree which asynchronously fetches children. If the dataset is large enough, there will then be a proportionately large number of fetches for the children.
### Reproduction
StackBlitz link: [stackblitz](https://stackblitz.com/edit/angular18-tree-duplicates-6iwee3dq?file=src%2Fmain.ts)
Notice how the tree eagerly fetches all children, including children of leaf nodes. The number on the bottom of the page indicates the number of times childrenAccessor was called.
### Expected Behavior
`childrenAccessor` should only be called when expanding a node.
Moreover, it should also *not* call the childrenAccessor for nodes which are not expandable, since we already provide the `when: hasChild` predicate.
### Actual Behavior
`childrenAccessor` is eagerly called for each node when the tree is created, including leaf nodes.
### Environment
- Angular: 20
- CDK/Material: 20
- Browser(s): Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): MacOS
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par la reproduction StackBlitz liée dans src/main.ts et vérifiez le nombre d’appels à childrenAccessor pour les nœuds extensibles et feuilles. Suivez l’implémentation de mat-tree responsable de ces appels, puis confirmez que les appels ne se produisent que lors de l’expansion et qu’ils sont ignorés pour les nœuds rejetés par le prédicat when.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- angular, typescript
- Domaine
- frontend
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100