Skip to content

Commit ca6697a

Browse files
committed
fix(core): re-cross only keyframed tweens, by less than GSAP's time step
A 1 us step still reached a stagger target 0.5 us in and a 0.4 us repeat, both sizes GSAP can represent. The step is now 2e-8: above GSAP's zero threshold, so the tween leaves its start, but below its 1e-7 time rounding, so the tween's own timeline does not move. Only keyframed tweens are re-crossed; a stagger is left as main renders it.
1 parent d279a5c commit ca6697a

2 files changed

Lines changed: 11 additions & 24 deletions

File tree

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,6 @@ describe("gsap adapter at a tween's start", () => {
105105
expect(gsap.getProperty(box, "x")).toBe(5);
106106
});
107107

108-
it("shows a staggered tween's start over an earlier tween's end", () => {
109-
const boxes = [0, 1].map(() => document.body.appendChild(document.createElement("div")));
110-
const timeline = gsap.timeline({ paused: true });
111-
timeline.from(boxes, { x: -60, duration: 2, ease: "none" }, 0);
112-
timeline.fromTo(boxes, { x: 5 }, { x: 60, duration: 1, stagger: 0.1 }, 2);
113-
const adapter = createGsapAdapter({
114-
getTimeline: () => timeline as unknown as RuntimeTimelineLike,
115-
});
116-
adapter.seek({ time: 2 });
117-
adapter.seek({ time: 2 });
118-
expect(gsap.getProperty(boxes[0]!, "x")).toBe(5);
119-
});
120-
121108
it("does not start a tween that begins just after the seek time", () => {
122109
const box = document.body.appendChild(document.createElement("div"));
123110
const timeline = gsap.timeline({ paused: true });
@@ -145,10 +132,10 @@ describe("gsap adapter at a tween's start", () => {
145132

146133
it.each([
147134
{
148-
shape: "a stagger whose next target starts 0.5 ms later with overwrite auto",
135+
shape: "a stagger whose next target starts 0.1 us later with overwrite auto",
149136
build: (timeline: gsap.core.Timeline, o: { x: number }) => {
150137
timeline.to(o, { x: 100, duration: 10, ease: "none" }, 0);
151-
timeline.to([{ x: 0 }, o], { x: 200, duration: 1, stagger: 0.0005, overwrite: "auto" }, 2);
138+
timeline.to([{ x: 0 }, o], { x: 200, duration: 1, stagger: 1e-7, overwrite: "auto" }, 2);
152139
},
153140
seeks: [2, 1],
154141
x: 10,
@@ -178,11 +165,11 @@ describe("gsap adapter at a tween's start", () => {
178165
x: 32.5,
179166
},
180167
{
181-
shape: "a short repeatRefresh keyframed tween",
168+
shape: "a 0.4 us repeatRefresh keyframed tween",
182169
build: (timeline: gsap.core.Timeline, o: { x: number }) => {
183170
const keyframes = [
184-
{ x: "+=10", duration: 0.0002 },
185-
{ x: "+=10", duration: 0.0002 },
171+
{ x: "+=10", duration: 2e-7 },
172+
{ x: "+=10", duration: 2e-7 },
186173
];
187174
timeline.to(o, { keyframes, repeat: 2, repeatRefresh: true, ease: "none" }, 2);
188175
},

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type GsapAdapterDeps = {
66

77
/**
88
* Re-renders a timeline already at `t`, silently, from just below (above at 0) so same-time steps apply in authored
9-
* order. That step skips a keyframes or stagger tween already at its start, so each one re-crosses its start alone.
9+
* order. That step skips a keyframed tween already at its start, so each one re-crosses its own start alone.
1010
*/
1111
export function rerenderGsapTimelineAt(
1212
timeline: {
@@ -26,11 +26,11 @@ type GsapAnimation = {
2626
totalDuration: () => number;
2727
paused: () => boolean;
2828
render: (totalTime: number, suppressEvents: boolean) => unknown;
29-
timeline?: unknown;
29+
vars?: { keyframes?: unknown };
3030
getChildren?: (nested: boolean, tweens: boolean, timelines: boolean) => unknown[];
3131
};
3232

33-
const STEP_PAST_START = 1e-6;
33+
const BELOW_GSAP_TIME_RESOLUTION = 2e-8;
3434

3535
const playsForward = (value: unknown): value is GsapAnimation => {
3636
const animation = value as GsapAnimation | null;
@@ -47,9 +47,9 @@ const playsForward = (value: unknown): value is GsapAnimation => {
4747
function recrossTweensStartingAt(children: unknown[], time: number): void {
4848
for (const child of children.filter(playsForward)) {
4949
const local = (time - child.startTime()) * child.timeScale();
50-
if (Math.abs(local) < 1e-9 && child.timeline) {
51-
child.render(STEP_PAST_START, true);
52-
child.render(-STEP_PAST_START, true);
50+
if (Math.abs(local) < 1e-9 && child.vars?.keyframes) {
51+
child.render(BELOW_GSAP_TIME_RESOLUTION, true);
52+
child.render(-BELOW_GSAP_TIME_RESOLUTION, true);
5353
child.render(0, true);
5454
} else if (child.getChildren && local > 0 && local <= child.totalDuration()) {
5555
recrossTweensStartingAt(child.getChildren(false, true, true), local);

0 commit comments

Comments
 (0)