From 38e94ac58a58e5300a8c091d72f20b42c177e1e2 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Sun, 14 Sep 2025 16:24:41 +0530 Subject: [PATCH] early return in second case --- src/client/app/router.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/client/app/router.ts b/src/client/app/router.ts index 996e6914..577fc0f1 100644 --- a/src/client/app/router.ts +++ b/src/client/app/router.ts @@ -289,15 +289,14 @@ export function scrollTo(hash: string, smooth = false, scrollPosition = 0) { target.focus({ preventScroll: true }) if (document.activeElement === target) return - // target is not focusable, make it temporarily focusable - const tabindex = target.getAttribute('tabindex') - target.setAttribute('tabindex', '-1') + if (target.hasAttribute('tabindex')) return const restoreTabindex = () => { - if (tabindex == null) target.removeAttribute('tabindex') - else target.setAttribute('tabindex', tabindex) + target.removeAttribute('tabindex') target.removeEventListener('blur', restoreTabindex) } + + target.setAttribute('tabindex', '-1') target.addEventListener('blur', restoreTabindex) target.focus({ preventScroll: true })