From 5aff328a9bd82a1eef639ca64a6dab212fc23a84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Mon, 18 May 2026 00:27:20 -0400 Subject: [PATCH] fix(producer): preserve inner root element when inlining sub-compositions The producer's inlineSubCompositions was not passing flattenInnerRoot, causing sub-composition inner root elements to be unwrapped during compilation. Scripts using #id selectors (rewritten to [data-hf-authored-id] by the scoping proxy) could not find their DOM root because the authored-id attribute was never set. The core bundler (bundleToSingleHtml) already passed flattenInnerRoot correctly. This aligns the producer's render compilation with the same behavior: clone the inner root, strip timing/composition attrs, replace id with data-hf-authored-id, and mark with data-hf-inner-root. --- .../producer/src/services/htmlCompiler.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/producer/src/services/htmlCompiler.ts b/packages/producer/src/services/htmlCompiler.ts index 533e04c7e..2203b764e 100644 --- a/packages/producer/src/services/htmlCompiler.ts +++ b/packages/producer/src/services/htmlCompiler.ts @@ -559,6 +559,19 @@ function inlineSubCompositions( if (!hosts.length) return html; + const FLATTENED_INNER_ROOT_STRIP_ATTRS = [ + "data-composition-id", + "data-composition-file", + "data-start", + "data-duration", + "data-end", + "data-track-index", + "data-track", + "data-composition-src", + "data-hf-authored-duration", + "data-hf-authored-end", + ]; + const result = inlineSubCompositionsShared( document as unknown as Document, hosts as unknown as Element[], @@ -574,6 +587,19 @@ function inlineSubCompositions( return compHtml; }, parseHtml: (htmlStr: string) => parseHTML(htmlStr).document as unknown as Document, + flattenInnerRoot: (innerRoot: Element): Element => { + const prepared = innerRoot.cloneNode(true) as Element; + const authoredRootId = prepared.getAttribute("id")?.trim(); + for (const attrName of FLATTENED_INNER_ROOT_STRIP_ATTRS) { + prepared.removeAttribute(attrName); + } + if (authoredRootId) { + prepared.removeAttribute("id"); + prepared.setAttribute("data-hf-authored-id", authoredRootId); + } + prepared.setAttribute("data-hf-inner-root", "true"); + return prepared; + }, scriptErrorLabel: "[Compiler] Composition script failed", }, );