Skip to content

Commit f4b4cd9

Browse files
committed
fix(tree) make change detection less often
The CdkTree component calls change detection after each node insert, which has impact on performance. The fix is to call change detection only once, when a set of nodes is rendered. Related bug: #11101
1 parent b67813e commit f4b4cd9

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/cdk/tree/tree.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,9 @@ describe('CdkTree', () => {
605605
try {
606606
TestBed.createComponent(NestedCdkErrorTreeApp).detectChanges();
607607
flush();
608-
} catch {
608+
} catch (e) {
609+
flush();
610+
} finally {
609611
flush();
610612
}
611613
}).toThrowError(getTreeControlFunctionsMissingError().message);

src/cdk/tree/tree.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ export class CdkTree<T> implements CollectionViewer, OnInit, OnDestroy {
287287
viewContainer.move(view!, currentIndex);
288288
}
289289
});
290+
291+
this._changeDetectorRef.detectChanges();
290292
}
291293

292294
/**
@@ -336,7 +338,5 @@ export class CdkTree<T> implements CollectionViewer, OnInit, OnDestroy {
336338
if (CdkTreeNode.mostRecentTreeNode) {
337339
CdkTreeNode.mostRecentTreeNode.data = nodeData;
338340
}
339-
340-
this._changeDetectorRef.detectChanges();
341341
}
342342
}

0 commit comments

Comments
 (0)