Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Sync from GitHub via hub-sync
Browse files
src/components/simple-videos-player.tsx
CHANGED
|
@@ -54,6 +54,19 @@ export const SimpleVideosPlayer = ({
|
|
| 54 |
firstVisibleIdxRef.current = firstVisibleIdx;
|
| 55 |
}, [firstVisibleIdx]);
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
// Initialize video refs array
|
| 58 |
useEffect(() => {
|
| 59 |
videoRefs.current = videoRefs.current.slice(0, videosInfo.length);
|
|
@@ -69,7 +82,7 @@ export const SimpleVideosPlayer = ({
|
|
| 69 |
if (resolved) return;
|
| 70 |
resolved = true;
|
| 71 |
setVideosReady(true);
|
| 72 |
-
|
| 73 |
setIsPlaying(true);
|
| 74 |
};
|
| 75 |
|
|
@@ -216,7 +229,9 @@ export const SimpleVideosPlayer = ({
|
|
| 216 |
// firstVisibleIdx intentionally omitted — we read it via ref so hiding
|
| 217 |
// the first camera doesn't reset readiness (see the comment near
|
| 218 |
// firstVisibleIdxRef above).
|
| 219 |
-
|
|
|
|
|
|
|
| 220 |
|
| 221 |
// Handle play/pause — skip hidden videos
|
| 222 |
useEffect(() => {
|
|
|
|
| 54 |
firstVisibleIdxRef.current = firstVisibleIdx;
|
| 55 |
}, [firstVisibleIdx]);
|
| 56 |
|
| 57 |
+
// Mirror onVideosReady into a ref for the same reason. Parents typically
|
| 58 |
+
// pass an inline arrow (`onVideosReady={() => setVideosReady(true)}`) which
|
| 59 |
+
// gets a new identity every render. Including it in the videos-ready
|
| 60 |
+
// effect's deps caused that effect to tear down + setup on every parent
|
| 61 |
+
// render. The setup branch then ran `queueMicrotask(handleLoadedData)` for
|
| 62 |
+
// every already-loaded video (true after the first load), seeking each
|
| 63 |
+
// back to segmentStart — videos got pinned on their first frame and never
|
| 64 |
+
// advanced.
|
| 65 |
+
const onVideosReadyRef = useRef(onVideosReady);
|
| 66 |
+
useEffect(() => {
|
| 67 |
+
onVideosReadyRef.current = onVideosReady;
|
| 68 |
+
}, [onVideosReady]);
|
| 69 |
+
|
| 70 |
// Initialize video refs array
|
| 71 |
useEffect(() => {
|
| 72 |
videoRefs.current = videoRefs.current.slice(0, videosInfo.length);
|
|
|
|
| 82 |
if (resolved) return;
|
| 83 |
resolved = true;
|
| 84 |
setVideosReady(true);
|
| 85 |
+
onVideosReadyRef.current?.();
|
| 86 |
setIsPlaying(true);
|
| 87 |
};
|
| 88 |
|
|
|
|
| 229 |
// firstVisibleIdx intentionally omitted — we read it via ref so hiding
|
| 230 |
// the first camera doesn't reset readiness (see the comment near
|
| 231 |
// firstVisibleIdxRef above).
|
| 232 |
+
// onVideosReady intentionally omitted — read via onVideosReadyRef so
|
| 233 |
+
// an inline parent prop doesn't tear this effect down on every render.
|
| 234 |
+
}, [videosInfo, setIsPlaying, seek]);
|
| 235 |
|
| 236 |
// Handle play/pause — skip hidden videos
|
| 237 |
useEffect(() => {
|