fix(webui): prevent initial scale fit layout race condition

This commit is contained in:
yiling
2026-06-30 10:45:51 +08:00
parent 7cb1aa3c86
commit d2ee7f1c45
@@ -376,8 +376,14 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
const [videoHtmlEl, setVideoHtmlEl] = useState<HTMLVideoElement | undefined>(undefined) const [videoHtmlEl, setVideoHtmlEl] = useState<HTMLVideoElement | undefined>(undefined)
const videoRef = useRef<HTMLVideoElement | null>(null) const videoRef = useRef<HTMLVideoElement | null>(null)
const [zoom, setZoom] = useState(1) const [zoom, setZoom] = useState(1)
const [hasManuallyZoomed, setHasManuallyZoomed] = useState(false)
const [containerSize, setContainerSize] = useState({ width: 0, height: 0 }) const [containerSize, setContainerSize] = useState({ width: 0, height: 0 })
const handleZoomChange = (newZoom: number) => {
setZoom(newZoom)
setHasManuallyZoomed(true)
}
// Store // Store
const { const {
isDrawing, isDrawing,
@@ -406,20 +412,17 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
return () => observer.disconnect() return () => observer.disconnect()
}, []) }, [])
// Fit to screen initial // Fit to screen initial / responsive resize
useEffect(() => { useEffect(() => {
if (containerSize.width > 0 && containerSize.height > 0) { if (containerSize.width > 0 && containerSize.height > 0) {
// Only if not already set or reset?
// Actually, we want to start fit.
const vidW = data.media?.metadata?.originalWidth ?? 1920 const vidW = data.media?.metadata?.originalWidth ?? 1920
const vidH = data.media?.metadata?.originalHeight ?? 1080 const vidH = data.media?.metadata?.originalHeight ?? 1080
const scale = Math.min(containerSize.width / vidW, containerSize.height / vidH) const scale = Math.min(containerSize.width / vidW, containerSize.height / vidH)
// Only set if zoom is 1 (initial). if (!hasManuallyZoomed) {
if (zoom === 1) {
setZoom(scale) setZoom(scale)
} }
} }
}, [containerSize.width, containerSize.height, data.media?.metadata]) }, [containerSize.width, containerSize.height, data.media?.metadata, hasManuallyZoomed])
// Cleanup ref when player is disposed // Cleanup ref when player is disposed
useEffect(() => { useEffect(() => {
@@ -922,7 +925,7 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
changeResolution={changeResolution} changeResolution={changeResolution}
handleDownload={handleDownload} handleDownload={handleDownload}
toggleFullScreen={toggleFullScreen} toggleFullScreen={toggleFullScreen}
onZoomChange={setZoom} onZoomChange={handleZoomChange}
frameRate={frameRate} frameRate={frameRate}
totalFrames={totalFrames} totalFrames={totalFrames}
currentFrame={currentFrame} currentFrame={currentFrame}