Skip to content

Commit be004b8

Browse files
authored
fix(cdk/tree): resolve maximum call stack error (angular#29754)
The CDK tree was calling `ChangeDetectorRef.detectChanges` recursively for each node in the tree which was overflowing the call stack with some larger trees. These changes resolve the issue by only calling `detectChanges` on the root. Fixes angular#29733.
1 parent 1bd976c commit be004b8

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/cdk/tree/tree.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,15 @@ export class CdkTree<T, K = T>
551551
}
552552
});
553553

554-
// TODO: change to `this._changeDetectorRef.markForCheck()`, or just switch this component to
555-
// use signals.
556-
this._changeDetectorRef.detectChanges();
554+
// Note: we only `detectChanges` from a top-level call, otherwise we risk overflowing
555+
// the call stack since this method is called recursively (see #29733.)
556+
// TODO: change to `this._changeDetectorRef.markForCheck()`,
557+
// or just switch this component to use signals.
558+
if (parentData) {
559+
this._changeDetectorRef.markForCheck();
560+
} else {
561+
this._changeDetectorRef.detectChanges();
562+
}
557563
}
558564

559565
/**

0 commit comments

Comments
 (0)