fix(session): delay jump-to-bottom button (#20853)

This commit is contained in:
Shoubhit Dash
2026-04-03 08:12:01 -05:00
committed by GitHub
parent 6359d00fb4
commit c307505f8b
2 changed files with 11 additions and 7 deletions
+8 -3
View File
@@ -347,6 +347,7 @@ export default function Page() {
scroll: { scroll: {
overflow: false, overflow: false,
bottom: true, bottom: true,
jump: false,
}, },
}) })
@@ -1247,13 +1248,17 @@ export default function Page() {
let scrollStateTarget: HTMLDivElement | undefined let scrollStateTarget: HTMLDivElement | undefined
let fillFrame: number | undefined let fillFrame: number | undefined
const jumpThreshold = (el: HTMLDivElement) => Math.max(400, el.clientHeight)
const updateScrollState = (el: HTMLDivElement) => { const updateScrollState = (el: HTMLDivElement) => {
const max = el.scrollHeight - el.clientHeight const max = el.scrollHeight - el.clientHeight
const distance = max - el.scrollTop
const overflow = max > 1 const overflow = max > 1
const bottom = !overflow || el.scrollTop >= max - 2 const bottom = !overflow || distance <= 2
const jump = overflow && distance > jumpThreshold(el)
if (ui.scroll.overflow === overflow && ui.scroll.bottom === bottom) return if (ui.scroll.overflow === overflow && ui.scroll.bottom === bottom && ui.scroll.jump === jump) return
setUi("scroll", { overflow, bottom }) setUi("scroll", { overflow, bottom, jump })
} }
const scheduleScrollState = (el: HTMLDivElement) => { const scheduleScrollState = (el: HTMLDivElement) => {
@@ -200,7 +200,7 @@ export function MessageTimeline(props: {
mobileChanges: boolean mobileChanges: boolean
mobileFallback: JSX.Element mobileFallback: JSX.Element
actions?: UserActions actions?: UserActions
scroll: { overflow: boolean; bottom: boolean } scroll: { overflow: boolean; bottom: boolean; jump: boolean }
onResumeScroll: () => void onResumeScroll: () => void
setScrollRef: (el: HTMLDivElement | undefined) => void setScrollRef: (el: HTMLDivElement | undefined) => void
onScheduleScrollState: (el: HTMLDivElement) => void onScheduleScrollState: (el: HTMLDivElement) => void
@@ -568,10 +568,9 @@ export function MessageTimeline(props: {
<div <div
class="absolute left-1/2 -translate-x-1/2 bottom-6 z-[60] pointer-events-none transition-all duration-200 ease-out" class="absolute left-1/2 -translate-x-1/2 bottom-6 z-[60] pointer-events-none transition-all duration-200 ease-out"
classList={{ classList={{
"opacity-100 translate-y-0 scale-100": "opacity-100 translate-y-0 scale-100": props.scroll.overflow && props.scroll.jump && !staging.isStaging(),
props.scroll.overflow && !props.scroll.bottom && !staging.isStaging(),
"opacity-0 translate-y-2 scale-95 pointer-events-none": "opacity-0 translate-y-2 scale-95 pointer-events-none":
!props.scroll.overflow || props.scroll.bottom || staging.isStaging(), !props.scroll.overflow || !props.scroll.jump || staging.isStaging(),
}} }}
> >
<button <button