Skip to content

Commit 528ffff

Browse files
committed
virtual-scroll: switch back to markForCheck since detectChanges
breaks viewports that are inside an `OnPush` component
1 parent c3e3dcb commit 528ffff

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
ViewEncapsulation,
2222
} from '@angular/core';
2323
import {animationFrameScheduler, fromEvent, Observable, Subject} from 'rxjs';
24-
import {sampleTime, take, takeUntil} from 'rxjs/operators';
24+
import {sampleTime, takeUntil} from 'rxjs/operators';
2525
import {CdkVirtualForOf} from './virtual-for-of';
2626
import {VIRTUAL_SCROLL_STRATEGY, VirtualScrollStrategy} from './virtual-scroll-strategy';
2727

@@ -301,11 +301,7 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
301301
if (!this._isChangeDetectionPending) {
302302
this._isChangeDetectionPending = true;
303303
this._ngZone.runOutsideAngular(() => Promise.resolve().then(() => {
304-
if (this._ngZone.isStable) {
305-
this._doChangeDetection();
306-
} else {
307-
this._ngZone.onStable.pipe(take(1)).subscribe(() => this._doChangeDetection());
308-
}
304+
this._doChangeDetection();
309305
}));
310306
}
311307
}
@@ -315,7 +311,7 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
315311
this._isChangeDetectionPending = false;
316312

317313
// Apply changes to Angular bindings.
318-
this._ngZone.run(() => this._changeDetectorRef.detectChanges());
314+
this._ngZone.run(() => this._changeDetectorRef.markForCheck());
319315
// Apply the content transform. The transform can't be set via an Angular binding because
320316
// bypassSecurityTrustStyle is banned in Google. However the value is safe, it's composed of
321317
// string literals, a variable that can only be 'X' or 'Y', and user input that is run through

src/demo-app/virtual-scroll/virtual-scroll-demo.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Component, ViewEncapsulation} from '@angular/core';
9+
import {ChangeDetectionStrategy, Component, ViewEncapsulation} from '@angular/core';
1010
import {BehaviorSubject} from 'rxjs';
1111

1212

@@ -22,6 +22,7 @@ type State = {
2222
templateUrl: 'virtual-scroll-demo.html',
2323
styleUrls: ['virtual-scroll-demo.css'],
2424
encapsulation: ViewEncapsulation.None,
25+
changeDetection: ChangeDetectionStrategy.OnPush,
2526
})
2627
export class VirtualScrollDemo {
2728
fixedSizeData = Array(10000).fill(50);

0 commit comments

Comments
 (0)