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 <noreply@anthropic.com>
This commit is contained in:
Vance Ingalls
2026-11-01 18:21:38 -08:00
co-authored by Claude Opus 5.5
parent a5e397a96d
commit 8829228be6
3 changed files with 29 additions and 20 deletions
@@ -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 };
}
@@ -143,6 +143,28 @@ function movingHost(attrs?: Record<string, string>) {
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 }) {
@@ -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();