diff --git a/src/cdk/tree/tree.ts b/src/cdk/tree/tree.ts index fe183fa8ea66..02b4f1bbbc83 100644 --- a/src/cdk/tree/tree.ts +++ b/src/cdk/tree/tree.ts @@ -551,9 +551,15 @@ export class CdkTree } }); - // TODO: change to `this._changeDetectorRef.markForCheck()`, or just switch this component to - // use signals. - this._changeDetectorRef.detectChanges(); + // Note: we only `detectChanges` from a top-level call, otherwise we risk overflowing + // the call stack since this method is called recursively (see #29733.) + // TODO: change to `this._changeDetectorRef.markForCheck()`, + // or just switch this component to use signals. + if (parentData) { + this._changeDetectorRef.markForCheck(); + } else { + this._changeDetectorRef.detectChanges(); + } } /**