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.

(cherry picked from commit be004b8)
  • Loading branch information
crisbeto committed Sep 18, 2024
1 parent 2cf2f53 commit 7db4b5f
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 @@ -550,9 +550,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 7db4b5f

Please sign in to comment.