bug(mat-tree): childrenAccessor is not lazily evaluated and leaf nodes are not filtered out before calling the childrenAccessor
- Vorherrschende Sprache
- TypeScript
- Sterne
- 25k
- Forks
- 6.8k
- Ø Merge
- 1 T. 8 Std.
- Gemergte PRs (30 T.)
- 91
Beschreibung
### 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
Beitragsleitfaden
Rechercherichtung
Beginne mit der verlinkten StackBlitz-Reproduktion unter src/main.ts und überprüfe die Anzahl der Aufrufe von childrenAccessor für aufklappbare und Blattknoten. Verfolge die mat-tree-Implementierung, die für diese Aufrufe verantwortlich ist, und bestätige anschließend, dass Aufrufe nur beim Aufklappen erfolgen und für Knoten, die vom when-Prädikat abgelehnt werden, übersprungen werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- angular, typescript
- Bereich
- frontend
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100