Skip to content
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

perf(module:resizable): mark mousedown and touchstart listeners as passive #7331

Merged
merged 1 commit into from Apr 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions components/resizable/resize-handle.component.ts
Expand Up @@ -3,6 +3,7 @@
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { normalizePassiveListenerOptions } from '@angular/cdk/platform';
import {
ChangeDetectionStrategy,
Component,
Expand Down Expand Up @@ -35,6 +36,8 @@ export class NzResizeHandleMouseDownEvent {
constructor(public direction: NzResizeDirection, public mouseEvent: MouseEvent | TouchEvent) {}
}

const passiveEventListenerOptions = <AddEventListenerOptions>normalizePassiveListenerOptions({ passive: true });

@Component({
selector: 'nz-resize-handle, [nz-resize-handle]',
exportAs: 'nzResizeHandle',
Expand Down Expand Up @@ -75,9 +78,12 @@ export class NzResizeHandleComponent implements OnInit {
});

this.ngZone.runOutsideAngular(() => {
// Note: since Chrome 56 defaults document level `touchstart` listener to passive.
// The element `touchstart` listener is not passive by default
// We never call `preventDefault()` on it, so we're safe making it passive too.
merge(
fromEvent<MouseEvent>(this.host.nativeElement, 'mousedown'),
fromEvent<TouchEvent>(this.host.nativeElement, 'touchstart')
fromEvent<MouseEvent>(this.host.nativeElement, 'mousedown', passiveEventListenerOptions),
fromEvent<TouchEvent>(this.host.nativeElement, 'touchstart', passiveEventListenerOptions)
)
.pipe(takeUntil(this.destroy$))
.subscribe((event: MouseEvent | TouchEvent) => {
Expand Down