Skip to content

Write HTML. Render video. Built for agents.

fix(producer): extract head assets from non-template sub-comps + fix postcss ESM (#220)

Miguel Ángelef2f646c9065
diff --git a/packages/producer/build.mjs b/packages/producer/build.mjs
index 2f497a6bd4..8d1bcfede9 100644
--- a/packages/producer/build.mjs
+++ b/packages/producer/build.mjs
@@ -36,7 +36,7 @@ await Promise.all([
platform: "node",
target: "node22",
format: "esm",
- external: ["puppeteer", "esbuild"],
+ external: ["puppeteer", "esbuild", "postcss"],
plugins: [workspaceAliasPlugin],
minify: false,
sourcemap: true,
@@ -48,7 +48,7 @@ await Promise.all([
platform: "node",
target: "node22",
format: "esm",
- external: ["puppeteer", "esbuild"],
+ external: ["puppeteer", "esbuild", "postcss"],
plugins: [workspaceAliasPlugin],
minify: false,
sourcemap: true,
diff --git a/packages/producer/src/services/htmlCompiler.ts b/packages/producer/src/services/htmlCompiler.ts
index 7ac6a0b53e..a737d6f232 100644
--- a/packages/producer/src/services/htmlCompiler.ts
+++ b/packages/producer/src/services/htmlCompiler.ts
@@ -525,6 +525,31 @@ function inlineSubCompositions(
: contentDoc.querySelector("[data-composition-id]");
const inferredCompId = innerRoot?.getAttribute("data-composition-id")?.trim() || null;
+ // When a sub-composition is a full HTML document (no <template>), styles
+ // and scripts in <head> are not part of contentDoc (which only has body
+ // content). Extract them separately so backgrounds, positioning, fonts,
+ // and library scripts (e.g. GSAP CDN) are not silently dropped.
+ if (!templateEl) {
+ const compHead = compDoc.querySelector("head");
+ if (compHead) {
+ for (const styleEl of compHead.querySelectorAll("style")) {
+ const css = rewriteCssAssetUrls(styleEl.textContent || "", srcPath);
+ const scopeId = compId || inferredCompId;
+ if (scopeId && css.trim()) {
+ collectedStyles.push(scopeCssToComposition(css, scopeId));
+ } else {
+ collectedStyles.push(css);
+ }
+ }
+ for (const scriptEl of compHead.querySelectorAll("script")) {
+ const src = (scriptEl.getAttribute("src") || "").trim();
+ if (src && !collectedExternalScriptSrcs.includes(src)) {
+ collectedExternalScriptSrcs.push(src);
+ }
+ }
+ }
+ }
+
for (const styleEl of contentDoc.querySelectorAll("style")) {
const css = rewriteCssAssetUrls(styleEl.textContent || "", srcPath);
const scopeId = compId || inferredCompId;