Skip to content

Commit 07415c8

Browse files
committed
fix(core): a call on the playhead fires once when a readiness pass runs
Start-up and readiness passes re-seek every adapter, including the GSAP adapter, which seeks the root timeline the root seek already renders. Its silent re-render re-armed a tl.call at the playhead, so the next forward seek fired it again. Which adapters the root seek leaves out is now one predicate used by all three adapter seeks.
1 parent 74d7698 commit 07415c8

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

‎packages/core/src/runtime/init.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,6 +2939,31 @@ describe("initSandboxRuntimeModular", () => {
29392939
vi.useRealTimers();
29402940
});
29412941

2942+
it("fires a call on the playhead once when a readiness pass runs between seeks", () => {
2943+
vi.useFakeTimers();
2944+
const root = document.createElement("div");
2945+
root.setAttribute("data-composition-id", "main");
2946+
root.setAttribute("data-root", "true");
2947+
root.setAttribute("data-start", "0");
2948+
root.setAttribute("data-duration", "10");
2949+
root.setAttribute("data-width", "1920");
2950+
root.setAttribute("data-height", "1080");
2951+
document.body.appendChild(root);
2952+
2953+
const fired = vi.fn();
2954+
const main = gsap.timeline({ paused: true }).to({ x: 0 }, { x: 1, duration: 10 });
2955+
main.call(fired, [], 2);
2956+
window.__timelines = { main };
2957+
initSandboxRuntimeModular();
2958+
2959+
window.__player?.renderSeek(2);
2960+
vi.runOnlyPendingTimers();
2961+
window.__player?.renderSeek(3);
2962+
2963+
expect(fired).toHaveBeenCalledTimes(1);
2964+
vi.useRealTimers();
2965+
});
2966+
29422967
it("shows pip video at global start time even when host composition starts late", () => {
29432968
// Regression: resolveStartForElement used to add the host composition's start on top of
29442969
// the video's own data-start, causing double-offset. A pip video with data-start="45.40"

‎packages/core/src/runtime/init.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3297,6 +3297,9 @@ export function initSandboxRuntimeModular(): void {
32973297
postState(true);
32983298
};
32993299

3300+
const isSeekedByRoot = (adapter: RuntimeDeterministicAdapter): boolean =>
3301+
adapter.name === "gsap" && Boolean(state.capturedTimeline);
3302+
33003303
const runAdapters = (
33013304
method: "discover" | "pause" | "play",
33023305
timeSeconds = 0,
@@ -3311,7 +3314,7 @@ export function initSandboxRuntimeModular(): void {
33113314
// keep runtime resilient against adapter-specific failures
33123315
swallow("runtime.init.site8", err);
33133316
}
3314-
if (method === "discover") {
3317+
if (method === "discover" && !isSeekedByRoot(adapter)) {
33153318
try {
33163319
adapter.seek({ time: timeSeconds, suppressEvents: true });
33173320
} catch (err) {
@@ -3968,7 +3971,7 @@ export function initSandboxRuntimeModular(): void {
39683971
onStatePost: postState,
39693972
onDeterministicSeek: (timeSeconds, options) => {
39703973
for (const adapter of state.deterministicAdapters) {
3971-
if (adapter.name === "gsap" && state.capturedTimeline) continue;
3974+
if (isSeekedByRoot(adapter)) continue;
39723975
try {
39733976
adapter.seek({
39743977
time: Number(timeSeconds) || 0,
@@ -4371,7 +4374,7 @@ export function initSandboxRuntimeModular(): void {
43714374
seekStandaloneRegisteredTimelines(t, opts);
43724375
const pageAnimations = pageAnimationsForOnePass();
43734376
for (const adapter of state.deterministicAdapters) {
4374-
if (adapter.name === "gsap" && tl) continue;
4377+
if (isSeekedByRoot(adapter)) continue;
43754378
try {
43764379
adapter.seek({ time: t, suppressEvents, pageAnimations });
43774380
} catch (err) {

0 commit comments

Comments
 (0)