+
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`),
+ `
`,
+ );
+ }
+ 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 || "";