Skip to content

Write HTML. Render video. Built for agents.

fix: preserve inferred composition ids when inlining

Miguel Ángeld3b2900d6b32
diff --git a/packages/producer/src/services/htmlCompiler.test.ts b/packages/producer/src/services/htmlCompiler.test.ts
index 6b62c29e7f..adcdd7921a 100644
--- a/packages/producer/src/services/htmlCompiler.test.ts
+++ b/packages/producer/src/services/htmlCompiler.test.ts
@@ -623,4 +623,42 @@ describe("template-wrapped sub-composition media offsets", () => {
expect(compiled.html).toContain("new Proxy(window.document");
expect(compiled.html).toContain("__hfNormalizeSelector");
});
+
+ it("preserves the inferred composition boundary when the host has no composition id", async () => {
+ const projectDir = mkdtempSync(join(tmpdir(), "hf-anonymous-host-"));
+ const compositionsDir = join(projectDir, "compositions");
+ mkdirSync(compositionsDir, { recursive: true });
+ writeFileSync(
+ join(projectDir, "index.html"),
+ `<!DOCTYPE html>
+<html>
+ <body>
+ <div id="root" data-composition-id="root" data-width="640" data-height="360">
+ <div id="scene-host" data-composition-src="compositions/scene.html" data-start="0"></div>
+ </div>
+ </body>
+</html>`,
+ );
+ writeFileSync(
+ join(compositionsDir, "scene.html"),
+ `<template id="scene-template">
+ <div data-composition-id="scene" data-width="640" data-height="360" data-duration="4">
+ <style>.title { opacity: 0; }</style>
+ <h1 class="title">Scene</h1>
+ <script>
+ window.__timelines = window.__timelines || {};
+ window.__timelines.scene = { duration: () => 4 };
+ </script>
+ </div>
+</template>`,
+ );
+
+ const compiled = await compileForRender(projectDir, join(projectDir, "index.html"), projectDir);
+ const { document } = parseHTML(compiled.html);
+ const host = document.querySelector("#scene-host");
+
+ expect(host?.getAttribute("data-composition-id")).toBe("scene");
+ expect(host?.querySelector(".title")?.textContent).toBe("Scene");
+ expect(compiled.html).toContain('var __hfCompId = "scene";');
+ });
});
diff --git a/packages/producer/src/services/htmlCompiler.ts b/packages/producer/src/services/htmlCompiler.ts
index cca2f9cbf4..34e2168e8e 100644
--- a/packages/producer/src/services/htmlCompiler.ts
+++ b/packages/producer/src/services/htmlCompiler.ts
@@ -650,8 +650,12 @@ function inlineSubCompositions(
);
if (innerRoot) {
+ const innerCompId = innerRoot.getAttribute("data-composition-id");
const innerW = innerRoot.getAttribute("data-width");
const innerH = innerRoot.getAttribute("data-height");
+ if (innerCompId && !host.getAttribute("data-composition-id")) {
+ host.setAttribute("data-composition-id", innerCompId);
+ }
if (innerW && !host.getAttribute("data-width")) host.setAttribute("data-width", innerW);
if (innerH && !host.getAttribute("data-height")) host.setAttribute("data-height", innerH);
innerRoot.querySelectorAll("style, script").forEach((el) => el.remove());