From 5a5df13bbdfe8575ef6b1fdd6df73d6100b82407 Mon Sep 17 00:00:00 2001 From: Artur Androsovych Date: Thu, 24 Feb 2022 04:34:29 +0200 Subject: [PATCH] perf(module:table): do not unnecessarily re-enter the Angular zone (#7142) --- components/table/src/table/tr-measure.component.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/components/table/src/table/tr-measure.component.ts b/components/table/src/table/tr-measure.component.ts index cb716e91eb..ee6a3391fa 100644 --- a/components/table/src/table/tr-measure.component.ts +++ b/components/table/src/table/tr-measure.component.ts @@ -69,9 +69,17 @@ export class NzTrMeasureComponent implements AfterViewInit, OnDestroy { takeUntil(this.destroy$) ) .subscribe(data => { - this.ngZone.run(() => { + // Caretaker note: we don't have to re-enter the Angular zone each time the stream emits. + // The below check is necessary to be sure that zone is not nooped through `BootstrapOptions` + // (`bootstrapModule(AppModule, { ngZone: 'noop' }))`. The `ngZone instanceof NgZone` may return + // `false` if zone is nooped, since `ngZone` will be an instance of the `NoopNgZone`. + // The `ResizeObserver` might be also patched through `zone.js/dist/zone-patch-resize-observer`, + // thus calling `ngZone.run` again will cause another change detection. + if (this.ngZone instanceof NgZone && NgZone.isInAngularZone()) { this.listOfAutoWidth.next(data); - }); + } else { + this.ngZone.run(() => this.listOfAutoWidth.next(data)); + } }); } ngOnDestroy(): void {