Skip to content

Commit 7db4b5f

Browse files
committed
fix(cdk/tree): resolve maximum call stack error (#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 #29733. (cherry picked from commit be004b8)
1 parent 2cf2f53 commit 7db4b5f

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
@@ -550,9 +550,15 @@ export class CdkTree<T, K = T>
550550
}
551551
});
552552

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

558564
/**

0 commit comments

Comments
 (0)