From a5e397a96dba9add097fcc97cbcc8c1bb9bdee44 Mon Sep 17 00:00:00 2001 From: Vance Ingalls Date: Sun, 1 Nov 2026 16:49:08 -0800 Subject: [PATCH] fix(core): a motion blur worker starting mid-film keeps the right state The mover scan walks the whole film with callbacks live, then seeks back to the worker's start. GSAP fires one-off calls in both directions, so a worker starting between two calls took the later call's state and held it until the next call. Going through 0 first gives every worker what frame 0 sees. Co-Authored-By: Claude Opus 5.5 --- .../runtime/captureMotionBlur/index.test.ts | 22 +++++++++++++++++++ .../src/runtime/captureMotionBlur/index.ts | 2 ++ 2 files changed, 24 insertions(+) diff --git a/packages/core/src/runtime/captureMotionBlur/index.test.ts b/packages/core/src/runtime/captureMotionBlur/index.test.ts index 62030e8f3c..e5ce165911 100644 --- a/packages/core/src/runtime/captureMotionBlur/index.test.ts +++ b/packages/core/src/runtime/captureMotionBlur/index.test.ts @@ -1038,6 +1038,28 @@ describe("painting", () => { expect(reads.every(([, suppress]) => suppress === false)).toBe(true); }); + 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"); + }); + it("fires timeline callbacks during discovery only when the root allows events", () => { for (const events of [true, false]) { installHtmlInCanvas(); diff --git a/packages/core/src/runtime/captureMotionBlur/index.ts b/packages/core/src/runtime/captureMotionBlur/index.ts index 7750c6fc7e..f40b9488b1 100644 --- a/packages/core/src/runtime/captureMotionBlur/index.ts +++ b/packages/core/src/runtime/captureMotionBlur/index.ts @@ -254,6 +254,8 @@ 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();