Skip to content

Commit 06ce6a8

Browse files
committed
fix(cdk-tree): fix crash in test cases with max call stack
Fix crash in test cases " An error was thrown in afterAll. RangeError: Maximum call stack size exceeded." example: https://app.circleci.com/pipelines/github/angular/components/58166/workflows/cc9e4f5d-2182-44a5-89a6-56f93e196843/jobs/506030 Fix crash when happened in expandAll and collapseAll methods. Use direct value of `_flattenedNodes` rather than subscribing to avoid unnecessary subscription. Using the value directly is safe because `_flattenedNodes` is a synchronous cache.
1 parent 38e48c7 commit 06ce6a8

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/cdk/tree/tree.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,9 @@ export class CdkTree<T, K = T>
643643
this.treeControl.expandAll();
644644
} else if (this._expansionModel) {
645645
const expansionModel = this._expansionModel;
646-
this._getAllNodes()
647-
.pipe(takeUntil(this._onDestroy))
648-
.subscribe(children => {
649-
expansionModel.select(...children.map(child => this._getExpansionKey(child)));
650-
});
646+
expansionModel.select(
647+
...this._flattenedNodes.value.map(child => this._getExpansionKey(child)),
648+
);
651649
}
652650
}
653651

@@ -657,11 +655,9 @@ export class CdkTree<T, K = T>
657655
this.treeControl.collapseAll();
658656
} else if (this._expansionModel) {
659657
const expansionModel = this._expansionModel;
660-
this._getAllNodes()
661-
.pipe(takeUntil(this._onDestroy))
662-
.subscribe(children => {
663-
expansionModel.deselect(...children.map(child => this._getExpansionKey(child)));
664-
});
658+
expansionModel.deselect(
659+
...this._flattenedNodes.value.map(child => this._getExpansionKey(child)),
660+
);
665661
}
666662
}
667663

src/material/tree/testing/tree-harness.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ interface ExampleFlatNode {
227227
{{node.name}}
228228
</mat-tree-node>
229229
<!-- This is the tree node template for expandable nodes -->
230-
<mat-tree-node *matTreeNodeDef="let node;when: flatTreeHasChild" matTreeNodePadding>
230+
<mat-tree-node *matTreeNodeDef="let node;when: flatTreeHasChild" matTreeNodePadding isExpandable>
231231
<button matTreeNodeToggle>
232232
Toggle
233233
</button>
@@ -240,7 +240,7 @@ interface ExampleFlatNode {
240240
{{node.name}}
241241
</mat-tree-node>
242242
<!-- This is the tree node template for expandable nodes -->
243-
<mat-nested-tree-node *matTreeNodeDef="let node; when: nestedTreeHasChild">
243+
<mat-nested-tree-node *matTreeNodeDef="let node; when: nestedTreeHasChild" isExpandable>
244244
<button matTreeNodeToggle>
245245
Toggle
246246
</button>

0 commit comments

Comments
 (0)