From 8829228be61d899bfc6e7331cfc5bdb8ce1778d6 Mon Sep 17 00:00:00 2001 From: Vance Ingalls Date: Sun, 1 Nov 2026 18:21:38 -0800 Subject: [PATCH] fix(core): rewind in the mover scan, so the filter tier gets it too Both tiers call scanMovers and then seek to the worker's start. Rewinding inside the scan covers them both, including the rescan after a tier handoff. Co-Authored-By: Claude Opus 5.5 --- .../src/runtime/captureMotionBlur/discover.ts | 2 + .../runtime/captureMotionBlur/index.test.ts | 45 +++++++++++-------- .../src/runtime/captureMotionBlur/index.ts | 2 - 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/packages/core/src/runtime/captureMotionBlur/discover.ts b/packages/core/src/runtime/captureMotionBlur/discover.ts index 8fb6f36a82..872295947d 100644 --- a/packages/core/src/runtime/captureMotionBlur/discover.ts +++ b/packages/core/src/runtime/captureMotionBlur/discover.ts @@ -300,6 +300,7 @@ export function scanMovers({ ...scan }: ScanOptions): Discovery & { readEvents: boolean } { const quiet = (t: number): void => seek(t, true); + const rewindThroughEveryCall = (): void => seek(0, false); if (!events) return { ...discoverMovers({ ...scan, seek: quiet, onStep }), readEvents: false }; // Loud first: run after the silent scan, it starts at the end and fires a one-off call once more. const loud: number[] = []; @@ -319,5 +320,6 @@ export function scanMovers({ differs ||= boxesKey(boxes) !== loud[i]; }, }); + rewindThroughEveryCall(); return { ...found, readEvents: differs }; } diff --git a/packages/core/src/runtime/captureMotionBlur/index.test.ts b/packages/core/src/runtime/captureMotionBlur/index.test.ts index e5ce165911..ae56a62eb3 100644 --- a/packages/core/src/runtime/captureMotionBlur/index.test.ts +++ b/packages/core/src/runtime/captureMotionBlur/index.test.ts @@ -143,6 +143,28 @@ function movingHost(attrs?: Record) { const PLAY = { playing: true }; +/** Paints 0.5 s first, as a mid-film worker does, over one-off calls at 0.3 s and 0.7 s. */ +function textAfterStartingAtHalf(): string { + const { h } = movingHost({ "data-motion-blur": "on", "data-motion-blur-events": "on" }); + const calls = [ + { at: 0.3, text: "first" }, + { at: 0.7, text: "second" }, + ]; + let head = 0; + let text = ""; + // GSAP fires a one-off call on a loud crossing in either direction. + const seek = (t: number, suppress: boolean) => { + h.seek(t, suppress); + const crossed = calls.filter(({ at }) => Math.min(head, t) < at && at <= Math.max(head, t)); + if (t < head) crossed.reverse(); + if (!suppress) for (const call of crossed) text = call.text; + head = t; + }; + initCaptureMotionBlur({ ...h, seek }); + void paintCaptureMotionBlur(0.5, PLAY); + return text; +} + describe("opt-in and off switches", () => { it("does nothing for a root that has not opted in", () => { installHtmlInCanvas(); @@ -1040,24 +1062,7 @@ describe("painting", () => { it("leaves a worker starting mid-film the state of the calls behind it, not ahead of it", () => { installHtmlInCanvas(); - const { h } = movingHost({ "data-motion-blur": "on", "data-motion-blur-events": "on" }); - const calls = [ - { at: 0.3, text: "first" }, - { at: 0.7, text: "second" }, - ]; - let head = 0; - let text = ""; - // GSAP fires a one-off call on a loud crossing in either direction. - const seek = (t: number, suppress: boolean) => { - h.seek(t, suppress); - const crossed = calls.filter(({ at }) => Math.min(head, t) < at && at <= Math.max(head, t)); - if (t < head) crossed.reverse(); - if (!suppress) for (const call of crossed) text = call.text; - head = t; - }; - initCaptureMotionBlur({ ...h, seek }); - void paintCaptureMotionBlur(0.5, PLAY); - expect(text).toBe("first"); + expect(textAfterStartingAtHalf()).toBe("first"); }); it("fires timeline callbacks during discovery only when the root allows events", () => { @@ -1762,6 +1767,10 @@ describe("paint timeouts", () => { describe("filter fallback", () => { beforeEach(() => setFilterFallbackForTests(true)); + it("leaves a worker starting mid-film the state of the calls behind it, not ahead of it", () => { + expect(textAfterStartingAtHalf()).toBe("first"); + }); + /** A root whose opacity tweens late, which a scan sees and capture cannot draw. */ const CAPTURE = { "data-motion-blur": "on", "data-motion-blur-tier": "capture" }; function fadingRoot(fade: { on: boolean }) { diff --git a/packages/core/src/runtime/captureMotionBlur/index.ts b/packages/core/src/runtime/captureMotionBlur/index.ts index f40b9488b1..7750c6fc7e 100644 --- a/packages/core/src/runtime/captureMotionBlur/index.ts +++ b/packages/core/src/runtime/captureMotionBlur/index.ts @@ -254,8 +254,6 @@ function createInstance(host: CaptureMotionBlurHost, config: Config, form: HtmlI events: config.events, onStep: (i, steps) => defects.sample(i, steps, (i / steps) * duration), }); - // Through 0, or a call behind restoreTo keeps the state the scan left. Workers start anywhere. - seek(0); seek(restoreTo); readEvents = found.readEvents; scanDefect = defects.result();