Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

refactor(preview): read the mounted source from the mirrors the rAF uses

EtienneLescot6f12b30f682c
diff --git a/src/components/ai-edition/VirtualPreview.tsx b/src/components/ai-edition/VirtualPreview.tsx
index 3d1e54ea8..884718e3d 100644
--- a/src/components/ai-edition/VirtualPreview.tsx
+++ b/src/components/ai-edition/VirtualPreview.tsx
@@ -217,8 +217,6 @@ export function VirtualPreview({
playbackClipsRef.current = playbackClips;
const videoSourcesRef = useRef(videoSources);
videoSourcesRef.current = videoSources;
- const activeSourceRef = useRef(activeSource);
- activeSourceRef.current = activeSource;
const sourceIndexRef = useRef(sourceIndex);
sourceIndexRef.current = sourceIndex;
const virtualTimeSecRef = useRef(virtualTimeSec);
@@ -595,8 +593,10 @@ export function VirtualPreview({
// `locateVirtualPosition` answers for whatever clip the playhead
// is on, which after a boundary advance can belong to a DIFFERENT
// asset — its source time would be a meaningless offset into the
- // file we are about to reload.
- const clipIsOnThisSource = position?.clip.assetId === activeSourceRef.current?.id;
+ // file we are about to reload. The mounted source is read from the
+ // same two mirrors the rAF tick uses, rather than kept in a third.
+ const clipIsOnThisSource =
+ position?.clip.assetId === videoSourcesRef.current[sourceIndexRef.current]?.id;
if (position && clipIsOnThisSource) {
// The rAF resumes against this; leaving it stale would resolve
// the next tick against the clip we were on before the failure.
@@ -631,7 +631,7 @@ export function VirtualPreview({
* failure point is the only honest evidence, and the rAF tick below owns it. */
const markSourceLoaded = useCallback(() => {
recoveringRef.current = false;
- const id = activeSourceRef.current?.id;
+ const id = videoSourcesRef.current[sourceIndexRef.current]?.id;
if (id) onVideoRecovered?.(id);
}, [onVideoRecovered]);