-
Notifications
You must be signed in to change notification settings - Fork 6.8k
virtual-scroll: use detectChanges rather than markForCheck in CdkVirtualScrollViewport
#12158
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
Conversation
`CdkVirtualScrollViewport`
|
So theoretically this should be a little better for performance, I think.. |
crisbeto
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| this._ngZone.runOutsideAngular(() => { | ||
| this._forOf = forOf; | ||
| this._forOf.dataStream.pipe(takeUntil(this._detachedSubject)).subscribe(data => { | ||
| const len = data.length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be called something like newLength?
| // It's still too early to measure the viewport at this point. Deferring with a promise allows | ||
| // the Viewport to be rendered with the correct size before we measure. | ||
| Promise.resolve().then(() => { | ||
| this._ngZone.runOutsideAngular(() => Promise.resolve().then(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expand comment to explain why you run outside the zone?
| private _destroyed = new Subject<void>(); | ||
|
|
||
| /** Whether there is a pending change detection cycle. */ | ||
| private _checkPending = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_isPendingChangeDetection or _needsChangeDetection?
| this._dataLength = len; | ||
| this._scrollStrategy.onDataLengthChanged(); | ||
| } | ||
| this._ngZone.runOutsideAngular(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment that explains why this is going out of the zone?
| private _doCheck() { | ||
| this._checkPending = false; | ||
| this._ngZone.run(() => this._changeDetectorRef.detectChanges()); | ||
| // In order to batch setting the scroll offset together with other DOM writes, we wait until a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite follow what this comment means about waiting, since detectChanges is synchronous
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but in the _markForCheck method above I'm batching them up using a Promise.resolve(). This way if we change multiple properties it waits until after they're all updated and calls detectChanges once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the comment live where the wait is scheduled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split the comment up to explain the batching part where it actually happens
| } | ||
|
|
||
| /** Run change detection. */ | ||
| private _doCheck() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call this method something like _detectChangesForScroll?
jelbourn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| } | ||
| } | ||
|
|
||
| for (let fn of this._runAfterChangeDetection) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use const instead of let
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 added fix to #12183
amcdnl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Is it merged in |
|
@naveedahmed1 You are right, it looks like this broke it for parents that are using |
…kVirtualScrollViewport` (#12158)
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |


No description provided.