Skip to content

Commit 7784054

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 b9a847f commit 7784054

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
@@ -644,11 +644,9 @@ export class CdkTree<T, K = T>
644644
this.treeControl.expandAll();
645645
} else if (this._expansionModel) {
646646
const expansionModel = this._expansionModel;
647-
this._getAllNodes()
648-
.pipe(takeUntil(this._onDestroy))
649-
.subscribe(children => {
650-
expansionModel.select(...children.map(child => this._getExpansionKey(child)));
651-
});
647+
expansionModel.select(
648+
...this._flattenedNodes.value.map(child => this._getExpansionKey(child)),
649+
);
652650
}
653651
}
654652

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

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)