fix(web): keep jump-to-bottom visible in history (#2304)

This commit is contained in:
Kiyoshi
2026-11-06 13:13:32 +08:00
committed by GitHub
parent 3ce46a9b13
commit 810aab72fc
4 changed files with 47 additions and 14 deletions
@@ -224,6 +224,25 @@ function renderSearchThread(options: {
}
describe('mobile initial scroll settling', () => {
it('shows the jump control during continuous upward scrolling and hides it at the bottom', () => {
const { viewport, queryByRole } = renderThread()
act(() => { vi.advanceTimersByTime(3_000) })
viewport.scrollTop = 702
fireEvent.scroll(viewport)
expect(queryByRole('button', { name: /scroll to bottom/i })).toBeNull()
viewport.scrollTop = 600
fireEvent.scroll(viewport)
expect(queryByRole('button', { name: /scroll to bottom/i })).not.toBeNull()
viewport.scrollTop = 400
fireEvent.scroll(viewport)
expect(queryByRole('button', { name: /scroll to bottom/i })).not.toBeNull()
viewport.scrollTop = 702
fireEvent.scroll(viewport)
expect(queryByRole('button', { name: /scroll to bottom/i })).toBeNull()
})
it('uses the explicit tail transition when a send requests a forced scroll', () => {
const onViewModeChange = vi.fn()
const onJumpToTail = vi.fn()
@@ -338,7 +338,7 @@ describe('scroll anchor helpers', () => {
})
})
it('shows the jump button only while scrolling down away from the bottom', () => {
it('shows the jump button in either direction away from the bottom', () => {
const downward = getScrollIntent({
scrollTop: 610,
previousScrollTop: 590,
@@ -360,7 +360,7 @@ describe('scroll anchor helpers', () => {
expect(downward.isScrollingDown).toBe(true)
expect(shouldShowScrollToBottomButton(downward)).toBe(true)
expect(shouldShowScrollToBottomButton(upward)).toBe(false)
expect(shouldShowScrollToBottomButton(upward)).toBe(true)
expect(shouldShowScrollToBottomButton(atBottom)).toBe(false)
})
@@ -370,7 +370,7 @@ describe('scroll anchor helpers', () => {
expect(shouldRenderScrollToBottomButton(false, 0)).toBe(false)
})
it('keeps the jump button visible after downward scrolling stops', () => {
it('keeps the jump button visible when scrolling stops or reverses', () => {
const downward = getScrollIntent({
scrollTop: 610,
previousScrollTop: 590,
@@ -392,7 +392,7 @@ describe('scroll anchor helpers', () => {
expect(getScrollToBottomButtonVisibility(false, downward)).toBe(true)
expect(getScrollToBottomButtonVisibility(true, stationary)).toBe(true)
expect(getScrollToBottomButtonVisibility(true, upward)).toBe(false)
expect(getScrollToBottomButtonVisibility(true, upward)).toBe(true)
})
it('cancels initial scroll settling when the user scrolls up away from the bottom', () => {
@@ -204,20 +204,14 @@ export function getScrollIntent(params: {
}
export function shouldShowScrollToBottomButton(intent: ScrollIntent): boolean {
return intent.isScrollingDown && !intent.isNearBottom
return !intent.isNearBottom
}
export function getScrollToBottomButtonVisibility(
wasVisible: boolean,
_wasVisible: boolean,
intent: ScrollIntent
): boolean {
if (intent.isNearBottom || intent.isScrollingUp) {
return false
}
if (intent.isScrollingDown) {
return true
}
return wasVisible
return shouldShowScrollToBottomButton(intent)
}
export function shouldRenderScrollToBottomButton(
@@ -1314,6 +1308,7 @@ export function HappyThread(props: {
if (isInitialScrollSettling()) {
setShowScrollToBottom(false)
if (shouldCancelInitialScrollSettling(intent, hadExplicitUpwardIntent)) {
setShowScrollToBottom(shouldShowScrollToBottomButton(intent))
initialScrollDeadlineRef.current = 0
clearInitialScrollTimers()
setAutoScrollMode(false)
@@ -1359,7 +1354,7 @@ export function HappyThread(props: {
if (intent.isScrollingUp && intent.distanceFromBottom > MANUAL_SCROLL_EPSILON_PX) {
tailScrollInProgressRef.current = false
setShowScrollToBottom(false)
setShowScrollToBottom(shouldShowScrollToBottomButton(intent))
setAutoScrollMode(false)
setAtBottomMode(false)
return