Skip to content

Commit 01c0bf4

Browse files
vanceingallsclaude
andauthored
fix(core): a motion blur worker starting mid-film keeps the right state (#6967)
* 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 <[email protected]> * 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 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 3bb0a9a commit 01c0bf4

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎packages/core/src/runtime/captureMotionBlur/discover.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ export function scanMovers({
300300
...scan
301301
}: ScanOptions): Discovery & { readEvents: boolean } {
302302
const quiet = (t: number): void => seek(t, true);
303+
const rewindThroughEveryCall = (): void => seek(0, false);
303304
if (!events) return { ...discoverMovers({ ...scan, seek: quiet, onStep }), readEvents: false };
304305
// Loud first: run after the silent scan, it starts at the end and fires a one-off call once more.
305306
const loud: number[] = [];
@@ -319,5 +320,6 @@ export function scanMovers({
319320
differs ||= boxesKey(boxes) !== loud[i];
320321
},
321322
});
323+
rewindThroughEveryCall();
322324
return { ...found, readEvents: differs };
323325
}

‎packages/core/src/runtime/captureMotionBlur/index.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,28 @@ function movingHost(attrs?: Record<string, string>) {
143143

144144
const PLAY = { playing: true };
145145

146+
/** Paints 0.5 s first, as a mid-film worker does, over one-off calls at 0.3 s and 0.7 s. */
147+
function textAfterStartingAtHalf(): string {
148+
const { h } = movingHost({ "data-motion-blur": "on", "data-motion-blur-events": "on" });
149+
const calls = [
150+
{ at: 0.3, text: "first" },
151+
{ at: 0.7, text: "second" },
152+
];
153+
let head = 0;
154+
let text = "";
155+
// GSAP fires a one-off call on a loud crossing in either direction.
156+
const seek = (t: number, suppress: boolean) => {
157+
h.seek(t, suppress);
158+
const crossed = calls.filter(({ at }) => Math.min(head, t) < at && at <= Math.max(head, t));
159+
if (t < head) crossed.reverse();
160+
if (!suppress) for (const call of crossed) text = call.text;
161+
head = t;
162+
};
163+
initCaptureMotionBlur({ ...h, seek });
164+
void paintCaptureMotionBlur(0.5, PLAY);
165+
return text;
166+
}
167+
146168
describe("opt-in and off switches", () => {
147169
it("does nothing for a root that has not opted in", () => {
148170
installHtmlInCanvas();
@@ -1038,6 +1060,11 @@ describe("painting", () => {
10381060
expect(reads.every(([, suppress]) => suppress === false)).toBe(true);
10391061
});
10401062

1063+
it("leaves a worker starting mid-film the state of the calls behind it, not ahead of it", () => {
1064+
installHtmlInCanvas();
1065+
expect(textAfterStartingAtHalf()).toBe("first");
1066+
});
1067+
10411068
it("fires timeline callbacks during discovery only when the root allows events", () => {
10421069
for (const events of [true, false]) {
10431070
installHtmlInCanvas();
@@ -1740,6 +1767,10 @@ describe("paint timeouts", () => {
17401767
describe("filter fallback", () => {
17411768
beforeEach(() => setFilterFallbackForTests(true));
17421769

1770+
it("leaves a worker starting mid-film the state of the calls behind it, not ahead of it", () => {
1771+
expect(textAfterStartingAtHalf()).toBe("first");
1772+
});
1773+
17431774
/** A root whose opacity tweens late, which a scan sees and capture cannot draw. */
17441775
const CAPTURE = { "data-motion-blur": "on", "data-motion-blur-tier": "capture" };
17451776
function fadingRoot(fade: { on: boolean }) {

0 commit comments

Comments
 (0)