-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
bug(drag-drop): Root element pointer down listeners causing excessive change detection #18726
bug(drag-drop): Root element pointer down listeners causing excessive change detection #18726
Comments
There are some data bindings that need to be updated once dragging starts (e.g. |
Good to know, I wasn't thinking about host bindings. But with the current implementation, I still don't see the need to run the pointerdown events inside
/** Handler that is invoked when the user moves their pointer after they've initiated a drag. */
private _pointerMove = (event: MouseEvent | TouchEvent) => {
// ...
if (!this._hasStartedDragging) {
//...
if (isOverThreshold) {
//...
if (!this._dropContainer || !this._dropContainer.isDragging()) {
this._hasStartedDragging = true;
this._ngZone.run(() => this._startDragSequence(event));
}
}
return;
}
//...
} Immediately following private _handleEvents(ref: DragRef<CdkDrag<T>>) {
ref.started.subscribe(() => {
this.started.emit({source: this});
// Since all of these events run outside of change detection,
// we need to ensure that everything is marked correctly.
this._changeDetectorRef.markForCheck();
});
//...
} Does anything else come to mind that relies on the pointerdown events being run insize |
Looking into it deeper, you're right that it's not necessary. I think this is a leftover from when dragging didn't have a threshold so it had to trigger change detection immediately. |
…vents When the drag&drop was initially implemented it had to trigger change detection immediately once dragging started so that the data bindings get updated correctly. After some time we introduced a threshold for dragging that also triggers its own change detection and makes the initial change detection unnecessary. Fixes angular#18726.
Great. Thanks for looking into it. |
…vents (#18821) When the drag&drop was initially implemented it had to trigger change detection immediately once dragging started so that the data bindings get updated correctly. After some time we introduced a threshold for dragging that also triggers its own change detection and makes the initial change detection unnecessary. Fixes #18726.
…vents (#18821) When the drag&drop was initially implemented it had to trigger change detection immediately once dragging started so that the data bindings get updated correctly. After some time we introduced a threshold for dragging that also triggers its own change detection and makes the initial change detection unnecessary. Fixes #18726. (cherry picked from commit 24a7c6d)
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. |
Reproduction
https://stackblitz.com/edit/angular-kwisjn?file=src/app/cdk-drag-drop-overview-example.html
The StackBlitz demo above is a slightly modified version of the "Basic Drag&Drop" official example with a change detection counter added and a second draggable box.
Simply clicking (and not even dragging) an element containing the
cdkDrag
directive causes app-wide change detection to occur. This behavior is exemplified by clicking the second box and witnessing the change detection counter increase.The first draggable box in the demo has had its root element listeners (
mousedown
andtouchstart
) modified to run outsize Angular zone.drag-ref.ts code:
Is there any reason these event listeners can't be instantiated outside the Angular zone? Like so:
Expected Behavior
No change detection occurs when simply clicking a draggable item.
Actual Behavior
Change detection occurs when simply clicking a draggable item.
Environment
The text was updated successfully, but these errors were encountered: