Skip to content

Commit 539c70c

Browse files
fix(core): a render no longer rewinds when a set sits beside a tween on another property (#7339)
1 parent ca64c2a commit 539c70c

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,26 @@ describe("a render where a set interrupts a running tween", () => {
205205
}
206206
});
207207
});
208+
209+
describe("a fromTo beside a set on another property of the same element", () => {
210+
it("renders forward without rewinding the timeline when the fromTo ends", () => {
211+
const tile = { x: 0, opacity: 1 };
212+
const real = gsap.timeline({ paused: true });
213+
real.fromTo(tile, { x: 0 }, { x: 100, duration: 1, ease: "none" }, 0);
214+
real.set(tile, { opacity: 0 }, 0);
215+
real.to(tile, { x: 200, duration: 1, ease: "none" }, 1);
216+
const landed: number[] = [];
217+
const timeline = producerStandIn(real);
218+
const totalTime = timeline.totalTime!;
219+
timeline.totalTime = ((...args: [number, boolean?]) => {
220+
if (args.length > 0) landed.push(args[0]);
221+
return totalTime(...args);
222+
}) as typeof totalTime;
223+
const structure = { owner: timeline, version: "1" };
224+
seekGsapTimeline(timeline, 0, true, structure, 30);
225+
landed.length = 0;
226+
for (const frame of range(1, 60)) seekGsapTimeline(timeline, frame / 30, true, structure, 30);
227+
expect(landed.filter((t, i) => i > 0 && t < landed[i - 1]!)).toEqual([]);
228+
expect(tile.x).toBeCloseTo(100 + 100 * (59 / 30 - 1), 5);
229+
});
230+
});

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ const NOT_PROPERTIES = new Set([
126126
"data",
127127
"inherit",
128128
"defaults",
129+
"parent",
129130
]);
130131
const EVERY_PROPERTY = new Set(["keyframes", "startAt", "transform"]);
131132
const SAME_PROPERTY: Record<string, string> = {
@@ -141,7 +142,17 @@ type PlacedTween = GsapPlaced & {
141142
};
142143
type PropertyWrite = { start: number; end: number; properties: Set<string> | null };
143144

144-
function propertiesWritten(vars: Record<string, unknown>): Set<string> | null {
145+
function propertiesWritten({ startAt, ...vars }: Record<string, unknown>): Set<string> | null {
146+
const to = ownPropertiesWritten(vars);
147+
if (startAt === undefined) return to;
148+
const from =
149+
startAt && typeof startAt === "object"
150+
? ownPropertiesWritten(startAt as Record<string, unknown>)
151+
: null;
152+
return to && from && new Set([...to, ...from]);
153+
}
154+
155+
function ownPropertiesWritten(vars: Record<string, unknown>): Set<string> | null {
145156
const properties = new Set<string>();
146157
for (const key of Object.keys(vars)) {
147158
if (EVERY_PROPERTY.has(key)) return null;

0 commit comments

Comments
 (0)