Skip to content

Commit 26523e6

Browse files
committed
fix(core): a pause inside a reversed repeating scene fires once after a redraw
The redraw renders a nested timeline the seek had left inactive, which marks it active. With its start-crossing mark restored but not its active flag, the next seek re-ran the scene's pause. The redraw now restores the active flag too.
1 parent 0e8fc39 commit 26523e6

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎packages/core/src/runtime/adapters/gsap.steps.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,23 @@ describe("re-rendering leaves the rest as the seek left it", () => {
327327
expect(draws(true)).toBe(draws(false));
328328
});
329329

330+
it("fires a pause in a reversed repeating scene as often as without the redraw", () => {
331+
const fires = (redraw: boolean) => {
332+
let fired = 0;
333+
const timeline = gsap.timeline({ paused: true }).to({ y: 0 }, { y: 1, duration: 10 });
334+
const scene = gsap.timeline({ repeat: 2, yoyo: true }).to({ z: 0 }, { z: 1, duration: 1 });
335+
scene.addPause(0, () => void fired++).timeScale(3);
336+
timeline.add(scene, 1);
337+
scene.reversed(true);
338+
timeline.progress(0.0001, true).totalTime(0, false);
339+
timeline.totalTime(3, true);
340+
if (redraw) rerenderGsapTimelineAt(timeline, 3);
341+
timeline.totalTime(2.99, false);
342+
return fired;
343+
};
344+
expect(fires(true)).toBe(fires(false));
345+
});
346+
330347
it("keeps the length of a timeline that grew after its last render", () => {
331348
const timeline = gsap.timeline({ paused: true }).to({ y: 0 }, { y: 1, duration: 10 });
332349
timeline.totalTime(1, true);

‎packages/core/src/runtime/adapters/gsap.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function rerenderGsapTimelineAt(
1919
timeline.totalDuration?.();
2020
const children = timeline.getChildren?.(false, true, true) ?? [];
2121
const marked = childrenWithLandingMarksIn(timeline).map(
22-
(child) => [child, child.ratio, child._zTime] as const,
22+
(child) => [child, child.ratio, child._zTime, child._act] as const,
2323
);
2424
const skipped = childrenStartingAfter(children, t).map((child) => [child, child._ts] as const);
2525
for (const [child] of skipped) child._ts = 0;
@@ -30,9 +30,10 @@ export function rerenderGsapTimelineAt(
3030
} finally {
3131
for (const [child, timeScale] of skipped) child._ts = timeScale;
3232
}
33-
for (const [child, ratio, zTime] of marked) {
33+
for (const [child, ratio, zTime, active] of marked) {
3434
child.ratio = ratio;
3535
child._zTime = zTime;
36+
child._act = active;
3637
}
3738
}
3839

@@ -57,7 +58,7 @@ function childrenStartingAfter(
5758
return found;
5859
}
5960

60-
type GsapLandingMarks = { ratio: number; _zTime?: number };
61+
type GsapLandingMarks = { ratio: number; _zTime?: number; _act?: number };
6162

6263
function childrenWithLandingMarksIn(timeline: {
6364
getChildren?: RuntimeTimelineLike["getChildren"];

0 commit comments

Comments
 (0)