diff --git a/CHANGELOG.md b/CHANGELOG.md
index cc160854..4605b357 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -48,6 +48,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
### Fixed
+- **video**: Fix playback stalling after tapping or clicking the progress bar on slow connections, and stop the hidden seek preview from downloading the whole video in the background.
- **cli**: Fix release publication failing to find staged standalone downloads.
### Changed
diff --git a/packages/webui/components/viewers/video/progress-bar.test.tsx b/packages/webui/components/viewers/video/progress-bar.test.tsx
new file mode 100644
index 00000000..ec163d94
--- /dev/null
+++ b/packages/webui/components/viewers/video/progress-bar.test.tsx
@@ -0,0 +1,138 @@
+// @vitest-environment happy-dom
+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
+import React from 'react'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import ProgressBar from './progress-bar'
+
+const TOTAL_FRAMES = 1000
+
+function renderBar(onSeek = vi.fn()) {
+ render(
+ ,
+ )
+ const bar = screen.getByTestId('seekbar')
+ vi.spyOn(bar, 'getBoundingClientRect').mockReturnValue({
+ left: 0,
+ right: 100,
+ top: 0,
+ bottom: 10,
+ width: 100,
+ height: 10,
+ x: 0,
+ y: 0,
+ toJSON: () => ({}),
+ } as DOMRect)
+ return { bar, onSeek }
+}
+
+function touchEvent(type: string, clientX: number, list: 'touches' | 'changedTouches') {
+ const event = new Event(type, { bubbles: true, cancelable: true })
+ Object.defineProperty(event, 'touches', {
+ value: list === 'touches' ? [{ clientX, clientY: 5 }] : [],
+ })
+ Object.defineProperty(event, 'changedTouches', {
+ value: list === 'changedTouches' ? [{ clientX, clientY: 5 }] : [],
+ })
+ return event
+}
+
+describe('ProgressBar seeking', () => {
+ beforeEach(() => {
+ vi.useFakeTimers({ toFake: ['Date'] })
+ vi.setSystemTime(new Date('2026-01-01T00:00:00Z'))
+ })
+
+ afterEach(() => {
+ cleanup()
+ vi.useRealTimers()
+ vi.restoreAllMocks()
+ })
+
+ it('seeks once for a plain click', () => {
+ const { bar, onSeek } = renderBar()
+
+ fireEvent.mouseDown(bar, { button: 0, clientX: 40 })
+ act(() => {
+ window.dispatchEvent(new MouseEvent('mouseup', { clientX: 40, clientY: 5 }))
+ })
+
+ expect(onSeek).toHaveBeenCalledTimes(1)
+ expect(onSeek).toHaveBeenLastCalledWith(400)
+ })
+
+ it('seeks again on release after a real drag', () => {
+ const { bar, onSeek } = renderBar()
+
+ fireEvent.mouseDown(bar, { button: 0, clientX: 40 })
+ act(() => {
+ window.dispatchEvent(new MouseEvent('mousemove', { clientX: 60 }))
+ window.dispatchEvent(new MouseEvent('mouseup', { clientX: 60, clientY: 5 }))
+ })
+
+ expect(onSeek.mock.calls.map(([frame]) => frame)).toEqual([400, 600, 600])
+ })
+
+ it('seeks once for a plain tap and ignores the synthetic mouse events that follow', () => {
+ const { bar, onSeek } = renderBar()
+
+ act(() => {
+ bar.dispatchEvent(touchEvent('touchstart', 30, 'touches'))
+ })
+ act(() => {
+ window.dispatchEvent(touchEvent('touchend', 30, 'changedTouches'))
+ })
+ vi.setSystemTime(new Date('2026-01-01T00:00:00.300Z'))
+ fireEvent.mouseDown(bar, { button: 0, clientX: 30 })
+
+ expect(onSeek).toHaveBeenCalledTimes(1)
+ expect(onSeek).toHaveBeenLastCalledWith(300)
+ })
+
+ it('accepts a mouse click again once the touch suppression window has passed', () => {
+ const { bar, onSeek } = renderBar()
+
+ act(() => {
+ bar.dispatchEvent(touchEvent('touchstart', 30, 'touches'))
+ })
+ act(() => {
+ window.dispatchEvent(touchEvent('touchend', 30, 'changedTouches'))
+ })
+ vi.setSystemTime(new Date('2026-01-01T00:00:01Z'))
+ fireEvent.mouseDown(bar, { button: 0, clientX: 70 })
+
+ expect(onSeek.mock.calls.map(([frame]) => frame)).toEqual([300, 700])
+ })
+
+ it('resets the drag without seeking when the touch is cancelled', () => {
+ const { bar, onSeek } = renderBar()
+
+ act(() => {
+ bar.dispatchEvent(touchEvent('touchstart', 30, 'touches'))
+ })
+ act(() => {
+ window.dispatchEvent(touchEvent('touchmove', 50, 'touches'))
+ })
+ act(() => {
+ window.dispatchEvent(new Event('touchcancel'))
+ })
+ act(() => {
+ window.dispatchEvent(touchEvent('touchmove', 80, 'touches'))
+ })
+
+ expect(onSeek.mock.calls.map(([frame]) => frame)).toEqual([300, 500])
+ })
+
+ it('loads only metadata for the hidden seek preview video', () => {
+ renderBar()
+
+ const preview = document.querySelector('video.hidden')
+ expect(preview).not.toBeNull()
+ expect(preview?.getAttribute('preload')).toBe('metadata')
+ })
+})
diff --git a/packages/webui/components/viewers/video/progress-bar.tsx b/packages/webui/components/viewers/video/progress-bar.tsx
index fc109a7a..6611e455 100644
--- a/packages/webui/components/viewers/video/progress-bar.tsx
+++ b/packages/webui/components/viewers/video/progress-bar.tsx
@@ -38,6 +38,15 @@ const ProgressBar: React.FC = ({
const [hoverPosition, setHoverPosition] = useState(null) // 0 to 1
const [isHovering, setIsHovering] = useState(false)
const [isDragging, setIsDragging] = useState(false)
+ // Tracks whether the pointer actually moved during a drag. A plain tap/click
+ // already seeks on pointer-down; re-seeking to the same frame on release
+ // restarts the native seek and stalls playback on slow connections.
+ const didDragMoveRef = useRef(false)
+ const lastSeekPosRef = useRef(null)
+ // After a touch interaction, mobile browsers fire synthetic mouse events
+ // (mousedown/mouseup) for the same tap. Suppress them so one tap does not
+ // trigger a second seek through the mouse path.
+ const lastTouchEndAtRef = useRef(0)
const onSeekRef = useRef(onSeek)
useEffect(() => {
@@ -92,8 +101,11 @@ const ProgressBar: React.FC = ({
const handleMouseDown = (e: React.MouseEvent) => {
if (e.button !== 0) return
+ if (Date.now() - lastTouchEndAtRef.current < 700) return
e.preventDefault()
setIsDragging(true)
+ didDragMoveRef.current = false
+ lastSeekPosRef.current = e.clientX
const percentage = getPercentageFromEvent(e.clientX)
setHoverPosition(percentage)
setIsHovering(true)
@@ -102,6 +114,8 @@ const ProgressBar: React.FC = ({
const handleTouchStart = (e: React.TouchEvent) => {
setIsDragging(true)
+ didDragMoveRef.current = false
+ lastSeekPosRef.current = e.touches[0].clientX
const percentage = getPercentageFromEvent(e.touches[0].clientX)
setHoverPosition(percentage)
setIsHovering(true)
@@ -112,6 +126,12 @@ const ProgressBar: React.FC = ({
if (!isDragging) return
const handleWindowMouseMove = (e: MouseEvent) => {
+ if (lastSeekPosRef.current !== null && Math.abs(e.clientX - lastSeekPosRef.current) >= 2) {
+ didDragMoveRef.current = true
+ lastSeekPosRef.current = e.clientX
+ } else if (!didDragMoveRef.current) {
+ return
+ }
const percentage = getPercentageFromEvent(e.clientX)
setHoverPosition(percentage)
setIsHovering(true)
@@ -147,12 +167,27 @@ const ProgressBar: React.FC = ({
setHoverPosition(null)
}
- const percentage = getPercentageFromEvent(e.clientX)
- onSeekRef.current(percentage * totalFrames)
+ // A plain click already seeked on mousedown; only seek again if the
+ // pointer actually moved (drag release position differs from start).
+ if (didDragMoveRef.current) {
+ const percentage = getPercentageFromEvent(e.clientX)
+ onSeekRef.current(percentage * totalFrames)
+ }
+ didDragMoveRef.current = false
+ lastSeekPosRef.current = null
}
const handleWindowTouchMove = (e: TouchEvent) => {
if (e.touches.length === 0) return
+ if (
+ lastSeekPosRef.current !== null &&
+ Math.abs(e.touches[0].clientX - lastSeekPosRef.current) >= 2
+ ) {
+ didDragMoveRef.current = true
+ lastSeekPosRef.current = e.touches[0].clientX
+ } else if (!didDragMoveRef.current) {
+ return
+ }
const percentage = getPercentageFromEvent(e.touches[0].clientX)
setHoverPosition(percentage)
setIsHovering(true)
@@ -172,6 +207,7 @@ const ProgressBar: React.FC = ({
const handleWindowTouchEnd = (e: TouchEvent) => {
setIsDragging(false)
+ lastTouchEndAtRef.current = Date.now()
const clientX = e.changedTouches.length > 0 ? e.changedTouches[0].clientX : null
const clientY = e.changedTouches.length > 0 ? e.changedTouches[0].clientY : null
@@ -191,22 +227,40 @@ const ProgressBar: React.FC = ({
setHoverPosition(null)
}
- if (clientX !== null) {
+ if (clientX !== null && didDragMoveRef.current) {
+ // A plain tap already seeked on touchstart; only seek again after a
+ // real drag so a single tap doesn't restart the seek and stall.
const percentage = getPercentageFromEvent(clientX)
onSeekRef.current(percentage * totalFrames)
}
+ didDragMoveRef.current = false
+ lastSeekPosRef.current = null
+ }
+
+ const handleWindowTouchCancel = () => {
+ // OS gestures (app switch, palm rejection, notification pull) cancel
+ // the touch. Reset drag state without seeking so the bar doesn't stay
+ // stuck in dragging/hover mode.
+ setIsDragging(false)
+ setIsHovering(false)
+ setHoverPosition(null)
+ didDragMoveRef.current = false
+ lastSeekPosRef.current = null
+ lastTouchEndAtRef.current = Date.now()
}
window.addEventListener('mousemove', handleWindowMouseMove)
window.addEventListener('mouseup', handleWindowMouseUp)
window.addEventListener('touchmove', handleWindowTouchMove, { passive: true })
window.addEventListener('touchend', handleWindowTouchEnd)
+ window.addEventListener('touchcancel', handleWindowTouchCancel)
return () => {
window.removeEventListener('mousemove', handleWindowMouseMove)
window.removeEventListener('mouseup', handleWindowMouseUp)
window.removeEventListener('touchmove', handleWindowTouchMove)
window.removeEventListener('touchend', handleWindowTouchEnd)
+ window.removeEventListener('touchcancel', handleWindowTouchCancel)
}
}, [isDragging, totalFrames, fps, getPercentageFromEvent])
@@ -269,7 +323,7 @@ const ProgressBar: React.FC = ({
ref={previewVideoRef}
src={previewUrl}
className="hidden"
- preload="auto"
+ preload="metadata"
muted
playsInline
/>