Skip to content

Commit c173919

Browse files
authored
refactor(material/table): Remove use of zone onStable in scheduling sticky column updates (#28651)
1 parent 438ff93 commit c173919

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/cdk/table/table.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ import {
5353
ViewEncapsulation,
5454
booleanAttribute,
5555
inject,
56+
afterNextRender,
57+
Injector,
5658
} from '@angular/core';
5759
import {
5860
BehaviorSubject,
@@ -62,7 +64,7 @@ import {
6264
Subject,
6365
Subscription,
6466
} from 'rxjs';
65-
import {take, takeUntil} from 'rxjs/operators';
67+
import {takeUntil} from 'rxjs/operators';
6668
import {CdkColumnDef} from './cell';
6769
import {_CoalescedStyleScheduler, _COALESCED_STYLE_SCHEDULER} from './coalesced-style-scheduler';
6870
import {
@@ -592,6 +594,8 @@ export class CdkTable<T>
592594
/** Row definition that will only be rendered if there's no data in the table. */
593595
@ContentChild(CdkNoDataRow) _noDataRow: CdkNoDataRow;
594596

597+
private _injector = inject(Injector);
598+
595599
constructor(
596600
protected readonly _differs: IterableDiffers,
597601
protected readonly _changeDetectorRef: ChangeDetectorRef,
@@ -614,11 +618,10 @@ export class CdkTable<T>
614618
@Inject(STICKY_POSITIONING_LISTENER)
615619
protected readonly _stickyPositioningListener: StickyPositioningListener,
616620
/**
617-
* @deprecated `_ngZone` parameter to become required.
618-
* @breaking-change 14.0.0
621+
* @deprecated `_unusedNgZone` parameter to be removed.
622+
* @breaking-change 19.0.0
619623
*/
620-
@Optional()
621-
protected readonly _ngZone?: NgZone,
624+
@Optional() _unusedNgZone?: NgZone,
622625
) {
623626
if (!role) {
624627
_elementRef.nativeElement.setAttribute('role', 'table');
@@ -732,15 +735,12 @@ export class CdkTable<T>
732735

733736
this._updateNoDataRow();
734737

735-
// Allow the new row data to render before measuring it.
736-
// @breaking-change 14.0.0 Remove undefined check once _ngZone is required.
737-
if (this._ngZone && NgZone.isInAngularZone()) {
738-
this._ngZone.onStable.pipe(take(1), takeUntil(this._onDestroy)).subscribe(() => {
738+
afterNextRender(
739+
() => {
739740
this.updateStickyColumnStyles();
740-
});
741-
} else {
742-
this.updateStickyColumnStyles();
743-
}
741+
},
742+
{injector: this._injector},
743+
);
744744

745745
this.contentChanged.next();
746746
}

tools/public_api_guard/cdk/table.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ export class CdkRowDef<T> extends BaseRowDef {
309309
export class CdkTable<T> implements AfterContentInit, AfterContentChecked, CollectionViewer, OnDestroy, OnInit {
310310
constructor(_differs: IterableDiffers, _changeDetectorRef: ChangeDetectorRef, _elementRef: ElementRef, role: string, _dir: Directionality, _document: any, _platform: Platform, _viewRepeater: _ViewRepeater<T, RenderRow<T>, RowContext<T>>, _coalescedStyleScheduler: _CoalescedStyleScheduler, _viewportRuler: ViewportRuler,
311311
_stickyPositioningListener: StickyPositioningListener,
312-
_ngZone?: NgZone | undefined);
312+
_unusedNgZone?: NgZone);
313313
addColumnDef(columnDef: CdkColumnDef): void;
314314
addFooterRowDef(footerRowDef: CdkFooterRowDef): void;
315315
addHeaderRowDef(headerRowDef: CdkHeaderRowDef): void;
@@ -360,8 +360,6 @@ export class CdkTable<T> implements AfterContentInit, AfterContentChecked, Colle
360360
ngOnDestroy(): void;
361361
// (undocumented)
362362
ngOnInit(): void;
363-
// @deprecated (undocumented)
364-
protected readonly _ngZone?: NgZone | undefined;
365363
_noDataRow: CdkNoDataRow;
366364
// (undocumented)
367365
_noDataRowOutlet: NoDataRowOutlet;

0 commit comments

Comments
 (0)