Skip to content

Commit

Permalink
fix: check for event.cancelable in touch events
Browse files Browse the repository at this point in the history
Chrome has started warning when canceling an event that cannot be cancelled, like scrolling.
This causes a fair bit of log spam. I know it fires for touchmove and touchend and there's 
reports that it also fires for touchstart.

    IgnoredEventCancel: intervention: Ignored attempt to cancel a touchmove event with
    cancelable=false, for example because scrolling is in progress and cannot be interrupted

References:

- react-grid-layout/react-draggable#553
- https://www.uriports.com/blog/easy-fix-for-intervention-ignored-attempt-to-cancel-a-touchmove-event-with-cancelable-false/
- FL3NKEY/scroll-lock#19
- https://stackoverflow.com/a/53315365/30900
  • Loading branch information
jschaf authored Jul 17, 2022
1 parent b83b763 commit c983970
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/signature_pad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ export default class SignaturePad extends SignatureEventTarget {

private _handleTouchStart = (event: TouchEvent): void => {
// Prevent scrolling.
event.preventDefault();
if (event.cancelable) {
event.preventDefault();
}

if (event.targetTouches.length === 1) {
const touch = event.changedTouches[0];
Expand All @@ -246,7 +248,9 @@ export default class SignaturePad extends SignatureEventTarget {

private _handleTouchMove = (event: TouchEvent): void => {
// Prevent scrolling.
event.preventDefault();
if (event.cancelable) {
event.preventDefault();
}

const touch = event.targetTouches[0];
this._strokeMoveUpdate(touch);
Expand All @@ -255,8 +259,9 @@ export default class SignaturePad extends SignatureEventTarget {
private _handleTouchEnd = (event: TouchEvent): void => {
const wasCanvasTouched = event.target === this.canvas;
if (wasCanvasTouched) {
event.preventDefault();

if (event.cancelable) {
event.preventDefault();
}
const touch = event.changedTouches[0];
this._strokeEnd(touch);
}
Expand Down

0 comments on commit c983970

Please sign in to comment.