Skip to content

Commit d8c7c48

Browse files
committed
Revert "perf(cdk/scrolling): do not run change detection if there are no viewChange listeners (#23987)"
This reverts commit ad33d7a.
1 parent ad33d7a commit d8c7c48

File tree

2 files changed

+1
-41
lines changed

2 files changed

+1
-41
lines changed

src/cdk/scrolling/virtual-for-of.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ export class CdkVirtualForOf<T>
199199
});
200200
this._viewport.renderedRangeStream.pipe(takeUntil(this._destroyed)).subscribe(range => {
201201
this._renderedRange = range;
202-
if (this.viewChange.observers.length) {
203-
ngZone.run(() => this.viewChange.next(this._renderedRange));
204-
}
202+
ngZone.run(() => this.viewChange.next(this._renderedRange));
205203
this._onRenderedDataChange();
206204
});
207205
this._viewport.attach(this);

src/cdk/scrolling/virtual-scroll-viewport.spec.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
ViewEncapsulation,
1616
Directive,
1717
ViewContainerRef,
18-
ApplicationRef,
1918
} from '@angular/core';
2019
import {
2120
waitForAsync,
@@ -787,43 +786,6 @@ describe('CdkVirtualScrollViewport', () => {
787786
}
788787
}).not.toThrow();
789788
}));
790-
791-
describe('viewChange change detection behavior', () => {
792-
let appRef: ApplicationRef;
793-
794-
beforeEach(inject([ApplicationRef], (ar: ApplicationRef) => {
795-
appRef = ar;
796-
}));
797-
798-
it('should not run change detection if there are no viewChange listeners', fakeAsync(() => {
799-
finishInit(fixture);
800-
testComponent.items = Array(10).fill(0);
801-
fixture.detectChanges();
802-
flush();
803-
804-
spyOn(appRef, 'tick');
805-
806-
viewport.scrollToIndex(5);
807-
triggerScroll(viewport);
808-
809-
expect(appRef.tick).not.toHaveBeenCalled();
810-
}));
811-
812-
it('should run change detection if there are any viewChange listeners', fakeAsync(() => {
813-
testComponent.virtualForOf.viewChange.subscribe();
814-
finishInit(fixture);
815-
testComponent.items = Array(10).fill(0);
816-
fixture.detectChanges();
817-
flush();
818-
819-
spyOn(appRef, 'tick');
820-
821-
viewport.scrollToIndex(5);
822-
triggerScroll(viewport);
823-
824-
expect(appRef.tick).toHaveBeenCalledTimes(1);
825-
}));
826-
});
827789
});
828790

829791
describe('with RTL direction', () => {

0 commit comments

Comments
 (0)