From 1be58d88313ef79b5e2cfa4ddd3854b9e18a44e9 Mon Sep 17 00:00:00 2001 From: Miguel Angel Simon Sierra Date: Mon, 9 Nov 2026 04:19:01 -0500 Subject: [PATCH 1/5] fix(core): a video held on its tail is seeked once, not every frame --- packages/core/src/runtime/media.test.ts | 18 ++++++++++++++++++ packages/core/src/runtime/media.ts | 10 +++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/core/src/runtime/media.test.ts b/packages/core/src/runtime/media.test.ts index a48a7dad082..109e4398bf5 100644 --- a/packages/core/src/runtime/media.test.ts +++ b/packages/core/src/runtime/media.test.ts @@ -1280,6 +1280,24 @@ describe("syncRuntimeMedia", () => { expect(clip.el.play).not.toHaveBeenCalled(); }); + it("seeks a held video tail once, though the browser lands short of the source end", () => { + // WebKit clamps a seek to the end onto the last frame, a few ms before the duration. + const clip = createMockClip({ start: 0, end: 5, duration: 5, sourceDuration: 0.25 }); + let time = 0; + const seeks: number[] = []; + Object.defineProperty(clip.el, "currentTime", { + get: () => time, + set: (value: number) => { + seeks.push(value); + time = Math.min(value, 0.2); + }, + configurable: true, + }); + for (const timeSeconds of [2, 2.02, 2.04, 2.06, 2.08]) + syncRuntimeMedia({ clips: [clip], timeSeconds, playing: true, playbackRate: 1 }); + expect(seeks).toHaveLength(1); + }); + it("holds a video that runs to the composition end on its last frame at the terminal time", () => { const clip = createMockClip({ start: 2.5, end: 5, duration: 2.5, sourceDuration: 10 }); const seek = { diff --git a/packages/core/src/runtime/media.ts b/packages/core/src/runtime/media.ts index 62fef2041a5..41551efa6c2 100644 --- a/packages/core/src/runtime/media.ts +++ b/packages/core/src/runtime/media.ts @@ -50,6 +50,9 @@ function frozenAudioFor(el: HTMLMediaElement, ct: number, now: number): number { } return now - m.at; } +// The source time a video was last sent to while held on its tail: a browser lands a seek to the end short of +// it, so asking again for the same time each tick would seek every frame. +const heldTailSeekedTo = new WeakMap(); const releaseHeldVideo = new WeakMap void>(); // A seeking video still paints its previous frame, and one still fetching its first data paints none (its seek @@ -309,6 +312,7 @@ function clampVolume(volume: number): number { * element at a different file without ever leaving its active window. */ export function evictMediaSyncState(el: HTMLMediaElement): void { + heldTailSeekedTo.delete(el); lastMoved.delete(el); lastOffset.delete(el); lastRelativeTime.delete(el); @@ -816,7 +820,9 @@ export function syncRuntimeMedia(params: { // ignore unsupported playbackRate swallow("runtime.media.site1", err); } - if (hardSync || strictSync || forceSync || (steerSeeks && !dipped)) { + // Already sent to this tail time: the browser landed short of it, and asking again would seek every tick. + const tailSettled = isHeldVideoTail && heldTailSeekedTo.get(el) === relTime; + if (!tailSettled && (hardSync || strictSync || forceSync || (steerSeeks && !dipped))) { // Skip the per-tick seek (and the `el.load()` drift-recovery retry // below) for `