From 401e2ce3c5ced4089b22c79605b5b8a3f6501811 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sat, 22 Mar 2025 12:12:08 +0100 Subject: [PATCH] [FEAT] block reload on scoll --- front/src/App.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/front/src/App.tsx b/front/src/App.tsx index 5a221c0..63b7370 100644 --- a/front/src/App.tsx +++ b/front/src/App.tsx @@ -1,3 +1,5 @@ +import { useEffect } from 'react'; + import { ErrorBoundary } from '@/errors/ErrorBoundary'; import { AudioPlayer } from './components'; @@ -6,6 +8,19 @@ import { AppRoutes } from './scene/AppRoutes'; import { ServiceContextProvider } from './service/ServiceContext'; export const App = () => { + // Prevent reload the page when scroll on mobile + useEffect(() => { + const preventRefresh = (event: { preventDefault: () => void }) => { + if (window.scrollY === 0) { + event.preventDefault(); + } + }; + document.addEventListener('touchmove', preventRefresh, { passive: false }); + return () => { + document.removeEventListener('touchmove', preventRefresh); + }; + }, []); + return (