Skip to content

Commit

Permalink
perf(module:table): do not unnecessarily re-enter the Angular zone (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
arturovt committed Feb 24, 2022
1 parent fc5c01e commit 5a5df13
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions components/table/src/table/tr-measure.component.ts
Expand Up @@ -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 {
Expand Down

0 comments on commit 5a5df13

Please sign in to comment.