diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 25c14101c..a1a7adfa8 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -629,12 +629,12 @@ return nav && (el === nav || nav.contains(el)); } - document.addEventListener('touchstart', (e) => { + const touchstartHandler = (e) => { if (!isNavOrDescendant(e.target)) return; touchstartY = e.touches[0].clientY; - }); + }; - document.addEventListener('touchmove', (e) => { + const touchmoveHandler = (e) => { if (!isNavOrDescendant(e.target)) return; const touchY = e.touches[0].clientY; const touchDiff = touchY - touchstartY; @@ -642,15 +642,19 @@ showRefresh = true; e.preventDefault(); } - }); + }; - document.addEventListener('touchend', (e) => { + const touchendHandler = (e) => { if (!isNavOrDescendant(e.target)) return; if (showRefresh) { showRefresh = false; location.reload(); } - }); + }; + + document.addEventListener('touchstart', touchstartHandler); + document.addEventListener('touchmove', touchmoveHandler, { passive: false }); + document.addEventListener('touchend', touchendHandler); if (typeof window !== 'undefined') { if (window.applyTheme) { @@ -842,11 +846,15 @@ return () => { window.removeEventListener('resize', onResize); + window.removeEventListener('message', windowMessageEventHandler); + document.removeEventListener('touchstart', touchstartHandler); + document.removeEventListener('touchmove', touchmoveHandler); + document.removeEventListener('touchend', touchendHandler); + document.removeEventListener('visibilitychange', handleVisibilityChange); }; }); onDestroy(() => { - window.removeEventListener('message', windowMessageEventHandler); bc.close(); });