Skip to content

Commit 773363d

Browse files
committed
fix(core): redraw only a scene timeline GSAP has never drawn
1 parent b41547c commit 773363d

3 files changed

Lines changed: 28 additions & 21 deletions

File tree

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -571,19 +571,6 @@ describe("seekGsapTimeline", () => {
571571
expect(moves - firstSeekMoves).toBe(2);
572572
});
573573

574-
it("redraws again after the timeline is cleared and rebuilt", () => {
575-
const film = hiddenAtZero();
576-
seekGsapTimeline(film.timeline, 0, false);
577-
const rebuilt = document.body.appendChild(document.createElement("span"));
578-
const gsapTimeline = film.timeline as unknown as gsap.core.Timeline;
579-
gsapTimeline
580-
.clear()
581-
.set(rebuilt, { visibility: "hidden" }, 0)
582-
.set(rebuilt, { visibility: "visible" }, 0.5);
583-
seekGsapTimeline(film.timeline, 0, false);
584-
expect(rebuilt.style.visibility).toBe("hidden");
585-
});
586-
587574
it("fires a call at that time once across the next seeks", () => {
588575
const film = hiddenAtZero();
589576
seekGsapTimeline(film.timeline, 0, false);

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ export function rerenderGsapTimelineAt(
4949
}
5050
}
5151

52-
const childrenAtLastInPlaceRedraw = new WeakMap<RuntimeTimelineLike, unknown[]>();
52+
type GsapRenderState = { _initted?: number };
53+
54+
function gsapNeverRendered(timeline: RuntimeTimelineLike): boolean {
55+
const [child] = (timeline.getChildren?.(false, true, true) ?? []) as { parent?: unknown }[];
56+
const rendered = child?.parent as GsapRenderState | undefined;
57+
return rendered !== undefined && !rendered._initted;
58+
}
5359

5460
export function seekGsapTimeline(
5561
timeline: RuntimeTimelineLike,
@@ -62,13 +68,7 @@ export function seekGsapTimeline(
6268
}
6369
const gsapSkipsRenderInPlace = Number(timeline.totalTime()) === t;
6470
timeline.totalTime(t, suppressEvents);
65-
if (!gsapSkipsRenderInPlace) return false;
66-
const children = timeline.getChildren?.(false, true, true) ?? [];
67-
const redrawn = childrenAtLastInPlaceRedraw.get(timeline);
68-
const unchangedSinceRedraw =
69-
redrawn?.length === children.length && children.every((child, i) => child === redrawn[i]);
70-
if (unchangedSinceRedraw) return false;
71-
childrenAtLastInPlaceRedraw.set(timeline, children);
71+
if (!gsapSkipsRenderInPlace || !gsapNeverRendered(timeline)) return false;
7272
rerenderGsapTimelineAt(
7373
{
7474
totalTime: timeline.totalTime.bind(timeline),

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3177,6 +3177,26 @@ describe("initSandboxRuntimeModular", () => {
31773177
expect(seekCalls).toEqual([{ time: 2, suppressEvents: false }]);
31783178
});
31793179

3180+
it("keeps a later root tween's value over a nested scene the root already drew", () => {
3181+
document.body.innerHTML = `<div data-composition-id="main" data-root="true" data-start="0" data-duration="2" data-width="1920" data-height="1080"><div data-composition-id="child" data-start="0" data-duration="2"><div id="box"></div></div></div>`;
3182+
const box = document.getElementById("box")!;
3183+
const options = { duration: 2, ease: "none", immediateRender: false, lazy: false };
3184+
const child = gsap.timeline({ smoothChildTiming: false });
3185+
child.fromTo(box, { opacity: 0 }, { ...options, opacity: 1, overwrite: false }, 0);
3186+
const main = gsap.timeline({ paused: true, smoothChildTiming: false });
3187+
main.add(child, 0);
3188+
main.fromTo(box, { opacity: 0.8 }, { ...options, opacity: 1, overwrite: false }, 0);
3189+
window.__timelines = { main, child };
3190+
initSandboxRuntimeModular();
3191+
3192+
window.__player?.renderSeek(1);
3193+
expect(Number(box.style.opacity)).toBeCloseTo(0.9, 5);
3194+
3195+
child.set({}, {}, 1.5);
3196+
window.__player?.renderSeek(1);
3197+
expect(Number(box.style.opacity)).toBeCloseTo(0.9, 5);
3198+
});
3199+
31803200
it("fires a call added after the first seek exactly once", () => {
31813201
const root = document.createElement("div");
31823202
root.setAttribute("data-composition-id", "main");

0 commit comments

Comments
 (0)