Skip to content

Commit 3e3ba8d

Browse files
fix(core): a set that interrupts a tween holds in a real render at any worker count (#7318)
1 parent a874a63 commit 3e3ba8d

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import gsap from "gsap";
22
import { describe, expect, it } from "vitest";
3-
import { seekGsapTimeline } from "./gsap";
3+
import { rerenderGsapTimelineAt, seekGsapTimeline } from "./gsap";
44
import { producerStandIn } from "./gsapStandIn.test-helpers";
55
import type { RuntimeTimelineLike } from "../types";
66

@@ -136,9 +136,45 @@ function panelAt(frames: number[], fps?: number, standIn = false): Map<number, n
136136
return opacity;
137137
}
138138

139+
/** The panel at each frame through both steps of a real seek: the seek, then the runtime's re-render. */
140+
function panelThroughRuntimeSeek(frames: number[], standIn = false): Map<number, number> {
141+
const { panel, timeline } = fadeInterruptedBySet(standIn);
142+
const opacity = new Map<number, number>();
143+
for (const frame of frames) {
144+
const t = frame / SET_FPS;
145+
if (!seekGsapTimeline(timeline, t, false, undefined, SET_FPS)) {
146+
rerenderGsapTimelineAt(
147+
{
148+
totalTime: timeline.totalTime!.bind(timeline),
149+
totalDuration: timeline.totalDuration?.bind(timeline),
150+
getChildren: timeline.getChildren?.bind(timeline),
151+
},
152+
t,
153+
);
154+
}
155+
opacity.set(frame, panel.opacity);
156+
}
157+
return opacity;
158+
}
159+
139160
describe("a render where a set interrupts a running tween", () => {
140161
const preview = panelAt(range(0, 90));
141162

163+
it("keeps the set's value through the runtime's re-render, however frames are shared out", () => {
164+
for (const standIn of [false, true]) {
165+
for (const workers of [1, 2, 3, 4, 6]) {
166+
for (let worker = 0; worker < workers; worker++) {
167+
for (const [frame, opacity] of panelThroughRuntimeSeek(
168+
range(worker, 90, workers),
169+
standIn,
170+
)) {
171+
if (frame >= SET_FPS) expect([workers, frame, opacity]).toEqual([workers, frame, 1]);
172+
}
173+
}
174+
}
175+
}
176+
});
177+
142178
it("lands every frame where preview does when one worker renders in order", () => {
143179
for (const [frame, opacity] of panelAt(range(0, 90), SET_FPS)) {
144180
expect([frame, opacity]).toEqual([frame, preview.get(frame)]);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ function renderOntoInAuthoredOrder(
5757
timeline.totalTime(below ? t - REDRAW_STEP : t + REDRAW_STEP, true);
5858
primeTweensStartingAt(children, t, below ? REDRAW_STEP : 0);
5959
timeline.totalTime(t, true);
60-
if (!below) reapplyStepsInAuthoredOrder(timeline, structure ?? ownStructureOf(children), t);
60+
const own = structure ?? ownStructureOf(children);
61+
if (!below) {
62+
reapplyStepsInAuthoredOrder(timeline, own, t);
63+
} else if (own) {
64+
settleOverlapsEndedBetween(own.owner as RuntimeTimelineLike, t - REDRAW_STEP, t, own.version);
65+
}
6166
}
6267

6368
function ownStructureOf(children: unknown[]): GsapStructureKey | undefined {

0 commit comments

Comments
 (0)