bug(mat-tree): childrenAccessor is not lazily evaluated and leaf nodes are not filtered out before calling the childrenAccessor
- Lenguaje dominante
- TypeScript
- Estrellas
- 25k
- Forks
- 6.8k
- Merge medio
- 1 d 8 h
- PR fusionados (30 d)
- 91
Descripción
### 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
Guía de contribución
Línea de trabajo
Comienza con la reproducción vinculada de StackBlitz en src/main.ts y verifica el número de llamadas a childrenAccessor para los nodos expandibles y hoja. Rastrea la implementación de mat-tree responsable de esas llamadas y confirma después que las llamadas solo se producen al expandir y se omiten para los nodos rechazados por el predicado when.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- angular, typescript
- Área
- frontend
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100