Skip to content

Commit defa68e

Browse files
committed
fix(core): a mounting scene never records the runtime's root timeline as its own
1 parent 673ef10 commit defa68e

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,24 @@ describe("the preview's scene window", () => {
20292029
expect(schedule.mock.calls.map(([el]) => el.getAttribute("src"))).toEqual(["/two.mp3"]);
20302030
});
20312031

2032+
it("records only what a mounting scene starts as its own, never the runtime's root", async () => {
2033+
const { root } = trackingRoot();
2034+
let onGlobal: unknown[] = [];
2035+
const own = { label: "late" };
2036+
(window as unknown as { gsap: unknown }).gsap = {
2037+
set: () => {},
2038+
globalTimeline: { getChildren: () => onGlobal },
2039+
};
2040+
// While s2's scripts run, the root lands on GSAP's global timeline, as a rebuild of it does, beside one of s2's own.
2041+
(window as unknown as { __lateStart: () => void }).__lateStart = () => (onGlobal = [root, own]);
2042+
bootWindowed([S0, S1, { ...S2, script: "window.__lateStart && window.__lateStart();" }], root);
2043+
window.__hfSceneAnimations = {};
2044+
await tick();
2045+
await seekAndSettle(5);
2046+
expect(window.__hfSceneAnimations?.s2).toEqual([own]);
2047+
delete (window as unknown as { gsap?: unknown }).gsap;
2048+
});
2049+
20322050
it("drops the decoded audio of a scene it parks", async () => {
20332051
const release = vi.spyOn(WebAudioTransport.prototype, "releaseDecodedExcept");
20342052
quietMedia();

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3952,10 +3952,19 @@ export function initSandboxRuntimeModular(): void {
39523952
);
39533953
// A timeline a scene's animation drives (a tween of its time, as tweenFromTo makes) is the scene's too, unless
39543954
// another owner registered it. A timeline the script built after it returned, after a font wait, is known only so.
3955-
const drivenBy = (animation: SceneAnimation, ids: string[]): SceneAnimation[] => {
3956-
const others = new Set<unknown>([state.capturedTimeline, window.gsap?.globalTimeline]);
3955+
// What is never a scene's own: the runtime's roots and the timelines other compositions registered.
3956+
const ownedElsewhere = (ids: string[]): Set<unknown> => {
3957+
const others = new Set<unknown>([
3958+
state.capturedTimeline,
3959+
window.gsap?.globalTimeline,
3960+
...builtRoots,
3961+
]);
39573962
for (const [id, timeline] of Object.entries(window.__timelines ?? {}))
39583963
if (!ids.includes(id)) others.add(timeline);
3964+
return others;
3965+
};
3966+
const drivenBy = (animation: SceneAnimation, ids: string[]): SceneAnimation[] => {
3967+
const others = ownedElsewhere(ids);
39593968
const tweens = animation.getChildren ? animation.getChildren(true, true, false) : [animation];
39603969
return tweens.flatMap((tween) =>
39613970
(tween.targets?.() ?? []).filter(
@@ -4018,7 +4027,8 @@ export function initSandboxRuntimeModular(): void {
40184027
// The gate lets a scene's script wait on fonts only, so their settling ends it.
40194028
await waitForFonts();
40204029
await new Promise((resolve) => window.setTimeout(resolve, 0));
4021-
const known = new Set<unknown>(Object.values(recorded).flat());
4030+
// The runtime rebuilds its root while the scene settles; that root, and other scenes' records, are not its.
4031+
const known = new Set<unknown>([...Object.values(recorded).flat(), ...ownedElsewhere([id])]);
40224032
const late = globalTimeline
40234033
.getChildren(false, true, true)
40244034
.filter((animation) => !before.has(animation) && !known.has(animation));

0 commit comments

Comments
 (0)