diff --git a/frontend/src/b/Shorts.tsx b/frontend/src/b/Shorts.tsx index 9555a03..9655d67 100644 --- a/frontend/src/b/Shorts.tsx +++ b/frontend/src/b/Shorts.tsx @@ -184,14 +184,24 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta // 처음 한 번: 시작 영상으로 맞추고, 뒤 페이지 스크롤을 잠근다 const startRef = useRef(start) - useEffect(() => { - // scrollIntoView 는 바깥 칸까지 굴려 버튼 줄이 헤더 밑으로 숨으므로 목록만 옮긴다 + // 시작 영상으로 옮기기 전엔 보이는 칸이 바뀐 것으로 치지 않는다 (사파리는 처음 그릴 때 맨 위 칸이 먼저 보여 첫 영상으로 바뀌던 것) + const placed = useRef(false) + useLayoutEffect(() => { + // scrollIntoView 는 바깥 칸까지 굴려 버튼 줄이 헤더 밑으로 숨으므로 목록만 옮긴다. 사파리는 첫 그림 전에 옮긴 값을 되돌려 한 번 더 const box = list.current - if (box) box.scrollTop = box.clientHeight * startRef.current + const place = () => { + if (box) box.scrollTop = box.clientHeight * startRef.current + } + place() + const raf = requestAnimationFrame(() => { + place() + placed.current = true + }) const root = document.documentElement const before = root.style.overflow root.style.overflow = 'hidden' return () => { + cancelAnimationFrame(raf) root.style.overflow = before } }, []) @@ -207,6 +217,7 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta if (!box) return const io = new IntersectionObserver( (entries) => { + if (!placed.current) return for (const e of entries) if (e.isIntersecting) setAt(Number((e.target as HTMLElement).dataset.i)) }, { root: box, threshold: 0.6 },