From 63bc3f4d5d31d00b22915f28caa14d670325c8db Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Thu, 23 Apr 2026 18:01:30 +0200 Subject: [PATCH] fix(mobile): scroll #main-app instead of body on mobile body/html have overflow:hidden so scrollTop is a no-op on them. #main-app is the actual scroll container; use overflow-y:auto on mobile and target it directly in scrollToNote and the scroll listener. --- src/App.vue | 2 +- src/hooks/useOverlay.hook.ts | 31 ++++++++++++++----------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/App.vue b/src/App.vue index 8968b57..57e871d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -28,7 +28,7 @@ const { isATProtoReady } = useATProtoLogin() @media screen and (max-width: 768px) { #main-app { - overflow: visible; + overflow-y: auto; } } diff --git a/src/hooks/useOverlay.hook.ts b/src/hooks/useOverlay.hook.ts index d7c4853..54aac26 100644 --- a/src/hooks/useOverlay.hook.ts +++ b/src/hooks/useOverlay.hook.ts @@ -10,31 +10,28 @@ export const useOverlay = (listen = true) => { const isMobile = computed(() => width.value <= MOBILE_BREAKPOINT) if (listen) { - // In Firefox/Chrome, body is the horizontal scroll container (body has - // computed overflow-x: auto from overflow-y: hidden). In Safari, the - // viewport (documentElement) is used instead. Listen on both. const updateScroll = () => { - x.value = document.body.scrollLeft || window.scrollX - y.value = document.body.scrollTop || window.scrollY + const mainApp = document.getElementById("main-app") + x.value = mainApp?.scrollLeft ?? 0 + y.value = mainApp?.scrollTop ?? 0 } - useEventListener(window, "scroll", updateScroll, { - passive: true, - capture: false - }) - useEventListener(document.body, "scroll", updateScroll, { - passive: true, - capture: false - }) + useEventListener( + () => document.getElementById("main-app"), + "scroll", + updateScroll, + { passive: true } + ) } const scrollToNote = (to: number) => { const go = () => { + const mainApp = document.getElementById("main-app") + if (!mainApp) return + if (isMobile.value) { - document.body.scrollTop = to - document.documentElement.scrollTop = to + mainApp.scrollTop = to } else { - document.body.scrollLeft = to - document.documentElement.scrollLeft = to + mainApp.scrollLeft = to } }