Fix LCP error:Does not use passive listeners to improve scrolling performance

This commit is contained in:
Paulo Gustavo Veiga 2022-08-13 08:59:19 -07:00
parent e13ec8bc30
commit 1eee80658c
2 changed files with 26 additions and 2 deletions

View File

@ -0,0 +1,15 @@
// Passive event listeners
function regiterTouchHandler(jQuery) {
jQuery.event.special.touchstart = {
setup: function (_, ns, handle) {
this.addEventListener("touchstart", handle, { passive: true });
}
};
jQuery.event.special.touchmove = {
setup: function (_, ns, handle) {
this.addEventListener("touchmove", handle, { passive: true });
}
};
}
export default regiterTouchHandler;

View File

@ -17,6 +17,12 @@
*/
import { $assert } from '@wisemapping/core-js';
import { Point } from '@wisemapping/web2d';
// https://stackoverflow.com/questions/60357083/does-not-use-passive-listeners-to-improve-scrolling-performance-lighthouse-repo
// https://web.dev/uses-passive-event-listeners/?utm_source=lighthouse&utm_medium=lr
// eslint-disable-next-line import/extensions
import regiterTouchHandler from '../../../../libraries/jquery.touchevent';
regiterTouchHandler($);
class ScreenManager {
private _divContainer: JQuery;
@ -63,8 +69,11 @@ class ScreenManager {
}
addEvent(eventType: string, listener) {
if (eventType === 'click') this._clickEvents.push(listener);
else this._divContainer.bind(eventType, listener);
if (eventType === 'click') {
this._clickEvents.push(listener);
} else {
this._divContainer.bind(eventType, listener);
}
}
removeEvent(event: string, listener) {