Skip to content

Commit 5a5df13

Browse files
authored
perf(module:table): do not unnecessarily re-enter the Angular zone (#7142)
1 parent fc5c01e commit 5a5df13

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

components/table/src/table/tr-measure.component.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,17 @@ export class NzTrMeasureComponent implements AfterViewInit, OnDestroy {
6969
takeUntil(this.destroy$)
7070
)
7171
.subscribe(data => {
72-
this.ngZone.run(() => {
72+
// Caretaker note: we don't have to re-enter the Angular zone each time the stream emits.
73+
// The below check is necessary to be sure that zone is not nooped through `BootstrapOptions`
74+
// (`bootstrapModule(AppModule, { ngZone: 'noop' }))`. The `ngZone instanceof NgZone` may return
75+
// `false` if zone is nooped, since `ngZone` will be an instance of the `NoopNgZone`.
76+
// The `ResizeObserver` might be also patched through `zone.js/dist/zone-patch-resize-observer`,
77+
// thus calling `ngZone.run` again will cause another change detection.
78+
if (this.ngZone instanceof NgZone && NgZone.isInAngularZone()) {
7379
this.listOfAutoWidth.next(data);
74-
});
80+
} else {
81+
this.ngZone.run(() => this.listOfAutoWidth.next(data));
82+
}
7583
});
7684
}
7785
ngOnDestroy(): void {

0 commit comments

Comments
 (0)