Skip to content

Commit

Permalink
fix(cdk/tree): resolve maximum call stack error (#29754)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crisbeto authored Sep 18, 2024
1 parent 1bd976c commit be004b8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/cdk/tree/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,15 @@ export class CdkTree<T, K = T>
}
});

// 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();
}
}

/**
Expand Down

0 comments on commit be004b8

Please sign in to comment.