From df8dae047fb50f87a5dbe718655318f335e7f6a1 Mon Sep 17 00:00:00 2001 From: Yared Yemane Date: Wed, 15 Apr 2026 04:34:34 -0700 Subject: [PATCH] improve human language scroll restore on refresh Retry scroll restoration until the page is tall enough so refreshes restore to the saved position smoothly, while keeping reduced-motion fallback. Made-with: Cursor --- .../content-management/HumanLanguagePage.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/pages/content-management/HumanLanguagePage.tsx b/src/pages/content-management/HumanLanguagePage.tsx index 453ca1f..bbce430 100644 --- a/src/pages/content-management/HumanLanguagePage.tsx +++ b/src/pages/content-management/HumanLanguagePage.tsx @@ -462,8 +462,19 @@ export function HumanLanguagePage() { const restoreBehavior = window.matchMedia("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth" - window.requestAnimationFrame(() => window.scrollTo({ top: targetY, behavior: restoreBehavior })) - setTimeout(() => window.scrollTo({ top: targetY, behavior: restoreBehavior }), 250) + let attempts = 0 + const maxAttempts = 14 + const tryRestore = () => { + if (cancelled) return + const maxScrollableY = Math.max(0, document.documentElement.scrollHeight - window.innerHeight) + if (maxScrollableY >= targetY || attempts >= maxAttempts) { + window.scrollTo({ top: targetY, behavior: restoreBehavior }) + return + } + attempts += 1 + window.setTimeout(tryRestore, 180) + } + window.requestAnimationFrame(tryRestore) } } catch (error) { console.error("Failed to load human-language hierarchy:", error)