From bff945e70132ee95ee6526db9a5eece6777d1dfa Mon Sep 17 00:00:00 2001 From: Royce59 Date: Sat, 1 Aug 2026 03:12:07 -0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D1=81=D0=BA=D1=80=D0=BE=D0=BB=D0=BB=20=D0=BA=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=8C=D0=B5=D0=BA=D1=82=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ScrollToTop/ScrollToTop.tsx | 41 ++++++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/components/ScrollToTop/ScrollToTop.tsx b/src/components/ScrollToTop/ScrollToTop.tsx index 8192001..7fd4b6f 100644 --- a/src/components/ScrollToTop/ScrollToTop.tsx +++ b/src/components/ScrollToTop/ScrollToTop.tsx @@ -5,15 +5,42 @@ export function ScrollToTop() { const { pathname, hash } = useLocation(); useEffect(() => { - const frame = window.requestAnimationFrame(() => { - if (hash) { - const target = document.getElementById(decodeURIComponent(hash.slice(1))); - if (target) { - target.scrollIntoView(); - return; - } + if (hash) { + let targetId: string; + + try { + targetId = decodeURIComponent(hash.slice(1)); + } catch { + targetId = hash.slice(1); } + const scrollToTarget = () => { + const target = document.getElementById(targetId); + + if (!target) { + return false; + } + + target.scrollIntoView({ block: 'start' }); + return true; + }; + + if (scrollToTarget()) { + return; + } + + const observer = new MutationObserver(() => { + if (scrollToTarget()) { + observer.disconnect(); + } + }); + + observer.observe(document.body, { childList: true, subtree: true }); + + return () => observer.disconnect(); + } + + const frame = window.requestAnimationFrame(() => { window.scrollTo({ top: 0, left: 0, behavior: 'instant' }); });