diff --git a/packages/producer/src/services/distributed/plan.test.ts b/packages/producer/src/services/distributed/plan.test.ts
index 9e149a35282..782bb6bb753 100644
--- a/packages/producer/src/services/distributed/plan.test.ts
+++ b/packages/producer/src/services/distributed/plan.test.ts
@@ -1624,3 +1624,73 @@ describe("plan() — webm format (distributed VP9)", () => {
expect((caught as Error).message).toMatch(/codec.*only valid for format="mp4"/);
});
});
+
+describe("plan() — template sub-composition entry", () => {
+ const TIMEOUT_MS = 30_000;
+ const INDEX_HTML = `
+
+

@@ -92,7 +91,6 @@ describe("runCompileStage — asset media-type preflight", () => {
runCompileStage({
projectDir,
workDir,
- htmlPath,
entryFile: "index.html",
job: {
id: "media-type-test",
diff --git a/packages/producer/src/services/render/stages/compileStage.test.ts b/packages/producer/src/services/render/stages/compileStage.test.ts
index 245124eac48..4aa158509b7 100644
--- a/packages/producer/src/services/render/stages/compileStage.test.ts
+++ b/packages/producer/src/services/render/stages/compileStage.test.ts
@@ -18,12 +18,13 @@
*/
import { afterEach, describe, expect, it } from "vitest";
-import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
import type { EngineConfig } from "@hyperframes/engine";
import type { CanvasResolution } from "@hyperframes/core";
import {
+ resolveEntryHtmlPath,
runCompileStage,
type CompileStageInput,
type CompileStageResult,
@@ -164,7 +165,6 @@ async function runWith(
const input: CompileStageInput = {
projectDir,
workDir: fixture.workDir,
- htmlPath: fixture.htmlPath,
entryFile: "index.html",
job: createJob(),
cfg,
@@ -260,7 +260,6 @@ describe("runCompileStage — master bus", () => {
const result = await runCompileStage({
projectDir: join(fixture.workDir, "project"),
workDir: fixture.workDir,
- htmlPath: fixture.htmlPath,
entryFile: "index.html",
job: createJob(),
cfg: createCfg(),
@@ -294,7 +293,6 @@ describe("runCompileStage — font fetch cancellation", () => {
const result = runCompileStage({
projectDir,
workDir: fixture.workDir,
- htmlPath: fixture.htmlPath,
entryFile: "index.html",
job: createJob(),
cfg: createCfg(),
@@ -345,7 +343,6 @@ describe("runCompileStage — aspect-agnostic --resolution re-map", () => {
const stageInput: CompileStageInput = {
projectDir,
workDir: fixture.workDir,
- htmlPath: fixture.htmlPath,
entryFile: "index.html",
job: createJob({
outputResolution: input.outputResolution,
@@ -472,3 +469,69 @@ describe("runCompileStage — aspect-agnostic --resolution re-map", () => {
).rejects.toThrow(/aspect ratio|--resolution portrait/i);
});
});
+
+describe("resolveEntryHtmlPath", () => {
+ const TEMPLATE = `
`;
+ let fixture: CompileFixture | null = null;
+
+ afterEach(() => {
+ fixture?.cleanup();
+ fixture = null;
+ });
+
+ function resolve(entryFile: string): string {
+ if (!fixture) throw new Error("fixture not set up");
+ return resolveEntryHtmlPath({
+ projectDir: join(fixture.workDir, "project"),
+ workDir: fixture.workDir,
+ entryFile,
+ log: noopLog,
+ });
+ }
+
+ it("returns a plain entry untouched and writes no wrapper", () => {
+ fixture = setupFixture(PLAIN_HTML);
+ expect(resolve("index.html")).toBe(fixture.htmlPath);
+ expect(existsSync(join(fixture.workDir, "standalone-entry.html"))).toBe(false);
+ });
+
+ it("returns a non-template sub-composition file untouched", () => {
+ fixture = setupFixture(PLAIN_HTML);
+ const subPath = join(fixture.workDir, "project", "full.html");
+ writeFileSync(subPath, PLAIN_HTML, "utf-8");
+ expect(resolve("full.html")).toBe(subPath);
+ });
+
+ it("isolates a mounted template entry inside the index shell", () => {
+ fixture = setupFixture(
+ `
+
+ `,
+ );
+ mkdirSync(join(fixture.workDir, "project", "compositions"));
+ writeFileSync(join(fixture.workDir, "project", "compositions", "scene.html"), TEMPLATE);
+ const wrapper = resolve("compositions/scene.html");
+ expect(wrapper).toBe(join(fixture.workDir, "standalone-entry.html"));
+ const html = readFileSync(wrapper, "utf-8");
+ expect(html).toContain('id="scene"');
+ expect(html).toContain('data-duration="2"');
+ expect(html).not.toContain('id="other"');
+ });
+
+ it("refuses a template entry that index.html does not mount", () => {
+ fixture = setupFixture(PLAIN_HTML);
+ mkdirSync(join(fixture.workDir, "project", "compositions"));
+ writeFileSync(join(fixture.workDir, "project", "compositions", "orphan.html"), TEMPLATE);
+ expect(() => resolve("compositions/orphan.html")).toThrow(/not mounted from index\.html/);
+ });
+
+ it("requires an index.html to extract a template entry's shell", () => {
+ fixture = setupFixture(PLAIN_HTML);
+ rmSync(fixture.htmlPath);
+ writeFileSync(join(fixture.workDir, "project", "scene.html"), TEMPLATE);
+ expect(() => resolve("scene.html")).toThrow(/requires a project index\.html/);
+ });
+});
diff --git a/packages/producer/src/services/render/stages/compileStage.ts b/packages/producer/src/services/render/stages/compileStage.ts
index 08957fcdb36..9440b67c273 100644
--- a/packages/producer/src/services/render/stages/compileStage.ts
+++ b/packages/producer/src/services/render/stages/compileStage.ts
@@ -35,9 +35,12 @@
* same behavior as before this PR.
*/
+import { existsSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import type { EngineConfig } from "@hyperframes/engine";
import { suggestMatchingPreset, type CanvasResolution } from "@hyperframes/core";
+import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
+import { readTextFile } from "@hyperframes/parsers/asset-resolution";
import type { CompiledComposition } from "../../htmlCompiler.js";
import { compileForRender } from "../../htmlCompiler.js";
import type { ProducerLogger } from "../../../logger.js";
@@ -53,9 +56,7 @@ import { preflightCompositionAssetMediaTypes } from "../../assetMediaType.js";
export interface CompileStageInput {
projectDir: string;
workDir: string;
- /** Absolute path to the entry HTML (already resolved to standalone-entry if needed). */
- htmlPath: string;
- /** The relative `entryFile` string, used only for log payloads. */
+ /** Entry HTML relative to `projectDir`; a `
` sub-composition is isolated inside the index shell. */
entryFile: string;
job: RenderJob;
/**
@@ -152,11 +153,48 @@ function adaptAspectAgnosticResolution(
return flipped;
}
+/**
+ * The HTML file to compile for `entryFile`. A ``-wrapped
+ * sub-composition has no live root, timeline or duration of its own, so it is
+ * rendered through the project's index.html shell with only its mount host kept.
+ */
+export function resolveEntryHtmlPath(input: {
+ projectDir: string;
+ workDir: string;
+ entryFile: string;
+ log: ProducerLogger;
+}): string {
+ const { projectDir, workDir, entryFile, log } = input;
+ const htmlPath = join(projectDir, entryFile);
+ const rawEntry = readTextFile(htmlPath);
+ if (entryFile === "index.html" || !isTemplateEntry(rawEntry)) return htmlPath;
+
+ const projectIndexPath = join(projectDir, "index.html");
+ if (!existsSync(projectIndexPath)) {
+ throw new Error(
+ `Template entry file "${entryFile}" requires a project index.html to extract its render shell.`,
+ );
+ }
+ const standaloneHtml = extractStandaloneEntryFromIndex(
+ readTextFile(projectIndexPath),
+ entryFile,
+ rawEntry,
+ );
+ if (!standaloneHtml) {
+ throw new Error(
+ `Entry file "${entryFile}" is not mounted from index.html via data-composition-src, so it cannot be rendered independently.`,
+ );
+ }
+ const wrapperPath = join(workDir, "standalone-entry.html");
+ writeFileSync(wrapperPath, standaloneHtml, "utf-8");
+ log.info("Extracted standalone entry from index.html host context", { entryFile });
+ return wrapperPath;
+}
+
export async function runCompileStage(input: CompileStageInput): Promise {
const {
projectDir,
workDir,
- htmlPath,
entryFile,
job,
cfg,
@@ -168,6 +206,7 @@ export async function runCompileStage(input: CompileStageInput): Promise wrapper), reuse the real
- // index.html shell and isolate the matching host instead of fabricating
- // a new standalone document.
- const rawEntry = readTextFile(htmlPath);
- if (entryFile !== "index.html" && isTemplateEntry(rawEntry)) {
- const wrapperPath = join(workDir, "standalone-entry.html");
- const projectIndexPath = join(projectDir, "index.html");
- if (!existsSync(projectIndexPath)) {
- throw new Error(
- `Template entry file "${entryFile}" requires a project index.html to extract its render shell.`,
- );
- }
- const standaloneHtml = extractStandaloneEntryFromIndex(
- readTextFile(projectIndexPath),
- entryFile,
- rawEntry,
- );
- if (!standaloneHtml) {
- throw new Error(
- `Entry file "${entryFile}" is not mounted from index.html via data-composition-src, so it cannot be rendered independently.`,
- );
- }
- writeFileSync(wrapperPath, standaloneHtml, "utf-8");
- htmlPath = wrapperPath;
- log.info("Extracted standalone entry from index.html host context", {
- entryFile,
- });
- }
-
// ── Stage 1: Compile ─────────────────────────────────────────────────
const stage1Start = Date.now();
updateJobStatus(job, "preprocessing", "Compiling composition", 5, onProgress, {
@@ -3289,7 +3258,6 @@ async function executeRenderPipeline(input: {
runCompileStage({
projectDir,
workDir,
- htmlPath,
entryFile,
job,
cfg,