Commit 53344d6e authored by Eduardo Sanz García's avatar Eduardo Sanz García Committed by Eduardo

Make listener passive

Chrome 89 printed the following warnings on the console:

```
shadow-root.js:67 [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive
```

See also: https://www.chromestatus.com/feature/5745543795965952

I have removed a listener that it isn't no longer needed, because it is wrapped in
a shadow DOM that already stop the bubbling up of the event.

Another 'touchstart' listener had the potential to slow down scrolling
on the host page on mobile devices. To avoid that we have made listener
passive.

These changes remove the warnings without affecting the current
behaviour of the application.
parent 121416fe
...@@ -241,9 +241,6 @@ export default class Sidebar { ...@@ -241,9 +241,6 @@ export default class Sidebar {
_setupGestures() { _setupGestures() {
const toggleButton = this.toolbar.sidebarToggleButton; const toggleButton = this.toolbar.sidebarToggleButton;
if (toggleButton) { if (toggleButton) {
// Prevent any default gestures on the handle.
this._listeners.add(toggleButton, 'touchmove', e => e.preventDefault());
this._hammerManager = new Hammer.Manager(toggleButton).on( this._hammerManager = new Hammer.Manager(toggleButton).on(
'panstart panend panleft panright', 'panstart panend panleft panright',
/* istanbul ignore next */ /* istanbul ignore next */
......
...@@ -49,7 +49,7 @@ export function createShadowRoot(container) { ...@@ -49,7 +49,7 @@ export function createShadowRoot(container) {
} }
/** /**
* Stop bubbling up of 'click' and 'touchstart' events. * Stop bubbling up of several events.
* *
* This makes the host page a little bit less aware of the annotator activity. * This makes the host page a little bit less aware of the annotator activity.
* It is still possible for the host page to manipulate the events on the capturing * It is still possible for the host page to manipulate the events on the capturing
...@@ -64,5 +64,7 @@ export function createShadowRoot(container) { ...@@ -64,5 +64,7 @@ export function createShadowRoot(container) {
function stopEventPropagation(element) { function stopEventPropagation(element) {
element.addEventListener('mouseup', event => event.stopPropagation()); element.addEventListener('mouseup', event => event.stopPropagation());
element.addEventListener('mousedown', event => event.stopPropagation()); element.addEventListener('mousedown', event => event.stopPropagation());
element.addEventListener('touchstart', event => event.stopPropagation()); element.addEventListener('touchstart', event => event.stopPropagation(), {
passive: true,
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment