From 7e717189c5f89e1bf36a267ecd734eaa608f012c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Wed, 4 Nov 2026 05:59:09 +0000 Subject: [PATCH] fix(core): a host inside a scene keeps its own timeline when its file shares a composition id (#7143) * test(core): two hosts in a scene whose files share an id get their own timelines * fix(core): a host inside a scene keeps its own timeline when its file shares a composition id * fix(core): the nested-host fallback is told by its docstring alone * fix(core): the identity map's docstring keeps its length --- .../__goldens__/pageBuild.preview.html | 6 +-- .../__goldens__/pageBuild.render.html | 6 +-- .../htmlBundler.nestedTimelines.test.ts | 50 +++++++++++++++++++ .../src/compiler/inlineSubCompositions.ts | 12 ++--- 4 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 packages/core/src/compiler/htmlBundler.nestedTimelines.test.ts diff --git a/packages/core/src/compiler/__goldens__/pageBuild.preview.html b/packages/core/src/compiler/__goldens__/pageBuild.preview.html index 829b29d955..2390ed4de6 100644 --- a/packages/core/src/compiler/__goldens__/pageBuild.preview.html +++ b/packages/core/src/compiler/__goldens__/pageBuild.preview.html @@ -88,7 +88,7 @@
Cell
-
+
New
@@ -98,7 +98,7 @@
Cell
-
+
New
@@ -108,7 +108,7 @@
Cell
-
+
New
diff --git a/packages/core/src/compiler/__goldens__/pageBuild.render.html b/packages/core/src/compiler/__goldens__/pageBuild.render.html index 3a7b550f38..5cd7e9abb4 100644 --- a/packages/core/src/compiler/__goldens__/pageBuild.render.html +++ b/packages/core/src/compiler/__goldens__/pageBuild.render.html @@ -114,7 +114,7 @@
Cell
-
+
New
@@ -124,7 +124,7 @@
Cell
-
+
New
@@ -134,7 +134,7 @@
Cell
-
+
New
diff --git a/packages/core/src/compiler/htmlBundler.nestedTimelines.test.ts b/packages/core/src/compiler/htmlBundler.nestedTimelines.test.ts new file mode 100644 index 0000000000..a08ca8b39d --- /dev/null +++ b/packages/core/src/compiler/htmlBundler.nestedTimelines.test.ts @@ -0,0 +1,50 @@ +// @vitest-environment node +import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { expect, it } from "vitest"; +import { bundleToSingleHtml } from "./htmlBundler.js"; + +/** Each script wrapper's runtime timeline key, in the bundle's order. */ +const timelineKeys = (html: string) => + [...html.matchAll(/var __hfTimelineCompId = "([^"]*)";/g)].map(([, id]) => id); + +// fails without the fix: two caption layers of one style inside a scene registered their timelines under the +// file's shared id, so the first take played the second take's words and the second played none. +it("gives each host inside a scene its own timeline, even when their files share a composition id", async () => { + const project = mkdtempSync(join(tmpdir(), "hf-nested-timelines-")); + try { + mkdirSync(join(project, "layers")); + writeFileSync( + join(project, "index.html"), + ` +
+
+
`, + ); + writeFileSync( + join(project, "captions.html"), + ``, + ); + for (const take of ["a", "b"]) { + writeFileSync( + join(project, "layers", `${take}.html`), + `
+

${take}

+ +
`, + ); + } + const bundled = await bundleToSingleHtml(project); + expect(timelineKeys(bundled)).toEqual(expect.arrayContaining(["take-a", "take-b"])); + expect(timelineKeys(bundled)).not.toContain("caption-style"); + } finally { + rmSync(project, { recursive: true, force: true }); + } +}); diff --git a/packages/core/src/compiler/inlineSubCompositions.ts b/packages/core/src/compiler/inlineSubCompositions.ts index 3e65a3b24a..74ab26555a 100644 --- a/packages/core/src/compiler/inlineSubCompositions.ts +++ b/packages/core/src/compiler/inlineSubCompositions.ts @@ -224,8 +224,8 @@ export interface InlineSubCompositionsOptions { /** * Identity map produced by `assignBundledRuntimeCompositionIds`. - * When provided, authoredCompositionId and runtimeCompositionId are read - * from this map instead of from the host element's attributes directly. + * When provided, a host's ids are read from this map; a host it lacks (one + * inside a scene) is read from its own attributes, as without a map. * The bundler uses this; the producer can omit it. */ hostIdentityMap?: Map< @@ -471,10 +471,10 @@ export function inlineSubCompositions( // Determine composition IDs let compId: string | null; let runtimeCompId: string; - if (hostIdentityMap) { - const identity = hostIdentityMap.get(hostEl); - compId = identity?.authoredCompositionId || null; - runtimeCompId = identity?.runtimeCompositionId || compId || ""; + const identity = hostIdentityMap?.get(hostEl); + if (identity) { + compId = identity.authoredCompositionId || null; + runtimeCompId = identity.runtimeCompositionId || compId || ""; } else { compId = hostEl.getAttribute("data-composition-id") || null; runtimeCompId = compId || "";