Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(module:table): do not unnecessarily re-enter the Angular zone #7142

Merged
merged 1 commit into from Feb 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions components/table/src/table/tr-measure.component.ts
Expand Up @@ -71,9 +71,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