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
This commit is contained in:
parent
1f0046a8ee
commit
df8dae047f
|
|
@ -462,8 +462,19 @@ export function HumanLanguagePage() {
|
||||||
const restoreBehavior = window.matchMedia("(prefers-reduced-motion: reduce)").matches
|
const restoreBehavior = window.matchMedia("(prefers-reduced-motion: reduce)").matches
|
||||||
? "auto"
|
? "auto"
|
||||||
: "smooth"
|
: "smooth"
|
||||||
window.requestAnimationFrame(() => window.scrollTo({ top: targetY, behavior: restoreBehavior }))
|
let attempts = 0
|
||||||
setTimeout(() => window.scrollTo({ top: targetY, behavior: restoreBehavior }), 250)
|
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) {
|
} catch (error) {
|
||||||
console.error("Failed to load human-language hierarchy:", error)
|
console.error("Failed to load human-language hierarchy:", error)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user