Skip to content

Commit 1aaa35d

Browse files
authored
fix(engine): detect onUpdate callbacks and enable verification events (#3794)
The static-frame dedup predictor walked tween intervals from window.__timelines but was blind to onUpdate callbacks — motion driven from a timeline's onUpdate in a tween-free window was predicted static. The verifier compounded the gap by seeking with suppressEvents: true, so the onUpdate never fired and the frozen frame passed verification. Two changes: 1. Predictor: when a timeline carries vars.onUpdate, mark its full span as animated so those frames are never predicted static. 2. Verifier: seek with suppressEvents: false so the verification page behaves identically to the capture page. The verification page is already isolated (separate Page instance), so out-of-order event side effects cannot corrupt sequential capture. Fixes #3793
1 parent 662f96b commit 1aaa35d

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎packages/engine/src/services/frameCapture-staticDedupVerifyDensity.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe("verifyStaticFramesSafe catches drift the old fixed-point density would
7070
expect(result.badFrame).toBe(changeAt);
7171
});
7272

73-
it("uses silent verification seeks and restores the playhead to frame zero", async () => {
73+
it("uses event-enabled verification seeks and restores the playhead to frame zero", async () => {
7474
const seekCalls: Array<{ t: number; options?: { suppressEvents?: boolean } }> = [];
7575
const page = {
7676
evaluate: vi.fn(async (fn: (tt: number) => void, t: number) => {
@@ -103,7 +103,7 @@ describe("verifyStaticFramesSafe catches drift the old fixed-point density would
103103

104104
expect(result.outcome).toBe("verified");
105105
expect(seekCalls.map((call) => Math.round(call.t * fps))).toEqual([0, 3, 0]);
106-
expect(seekCalls.every((call) => call.options?.suppressEvents === true)).toBe(true);
106+
expect(seekCalls.every((call) => call.options?.suppressEvents === false)).toBe(true);
107107
});
108108

109109
it("disarms within a wall-clock budget instead of spending minutes verifying a long static run", async () => {

‎packages/engine/src/services/frameCapture.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2736,6 +2736,13 @@ export async function computeStaticFrameSet(
27362736
let hasTimelineCall = false;
27372737
function walk(tl: AnyTween, offset: number): void {
27382738
if (typeof tl.getChildren !== "function") return;
2739+
// A timeline with an onUpdate callback can drive motion without any
2740+
// visible tween (e.g. setting x/y from Math.random inside onUpdate).
2741+
// Mark its entire span as animated so those frames are never deduped.
2742+
if (typeof tl.vars?.onUpdate === "function") {
2743+
const total = typeof tl.totalDuration === "function" ? tl.totalDuration() : 0;
2744+
if (total > 0) intervals.push({ start: offset, end: offset + total });
2745+
}
27392746
for (const child of tl.getChildren(false, true, true)) {
27402747
const start = offset + (typeof child.startTime === "function" ? child.startTime() : 0);
27412748
const single = typeof child.duration === "function" ? child.duration() : 0;
@@ -3054,8 +3061,9 @@ interface StaticVerificationDependencies {
30543061

30553062
/**
30563063
* Prepare an isolated page for static-frame verification. Verification seeks
3057-
* intentionally visit frames out of capture order, so they must never mutate
3058-
* the page that will later be captured sequentially.
3064+
* intentionally visit frames out of capture order on a SEPARATE page that is
3065+
* never used for the real capture — out-of-order event-callback side effects
3066+
* are contained to this disposable page and cannot corrupt sequential capture.
30593067
*/
30603068
export async function createStaticVerificationPage(session: CaptureSession): Promise<Page> {
30613069
const page = await session.browser.newPage();
@@ -3167,7 +3175,7 @@ export async function verifyStaticFramesSafe(
31673175
__hf?: { seek?: (t: number, options?: { suppressEvents?: boolean }) => void };
31683176
}
31693177
).__hf;
3170-
if (hf && typeof hf.seek === "function") hf.seek(tt, { suppressEvents: true });
3178+
if (hf && typeof hf.seek === "function") hf.seek(tt, { suppressEvents: false });
31713179
}, t);
31723180
};
31733181
const hardCap = Math.max(

0 commit comments

Comments
 (0)