mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 04:38:33 +00:00
fix: preserve original rel attribute on sub-composition link extraction
Store {href, rel, crossorigin} from source <link> elements instead of
re-deriving rel from a URL substring heuristic. Fixes preview-vs-render
parity: a stylesheet link whose href lacks ".css" or "css2?" was
emitted as preconnect in the compiled output, silently dropping the font.
Also documents that caption components ship with transparent backgrounds
intentionally — users add contrast layers in the host composition.
This commit is contained in:
@@ -685,7 +685,7 @@ export async function bundleToSingleHtml(
|
||||
const compStyleChunks: string[] = [...subCompResult.styles];
|
||||
const compScriptChunks: string[] = [...subCompResult.scripts];
|
||||
const compExternalScriptSrcs: string[] = [...subCompResult.externalScriptSrcs];
|
||||
const compExternalLinkHrefs: string[] = [...subCompResult.externalLinkHrefs];
|
||||
const compExternalLinks = [...subCompResult.externalLinks];
|
||||
const compVariablesByComp: Record<string, Record<string, unknown>> = {
|
||||
...subCompResult.variablesByComp,
|
||||
};
|
||||
@@ -812,14 +812,12 @@ export async function bundleToSingleHtml(
|
||||
}
|
||||
}
|
||||
|
||||
for (const href of compExternalLinkHrefs) {
|
||||
if (!document.querySelector(`link[href="${href}"]`)) {
|
||||
for (const link of compExternalLinks) {
|
||||
if (!document.querySelector(`link[href="${link.href}"]`)) {
|
||||
const linkEl = document.createElement("link");
|
||||
linkEl.setAttribute(
|
||||
"rel",
|
||||
href.includes(".css") || href.includes("css2?") ? "stylesheet" : "preconnect",
|
||||
);
|
||||
linkEl.setAttribute("href", href);
|
||||
linkEl.setAttribute("rel", link.rel);
|
||||
linkEl.setAttribute("href", link.href);
|
||||
if (link.crossorigin != null) linkEl.setAttribute("crossorigin", link.crossorigin);
|
||||
document.head.appendChild(linkEl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ export interface InlineSubCompositionsResult {
|
||||
styles: string[];
|
||||
scripts: string[];
|
||||
externalScriptSrcs: string[];
|
||||
externalLinkHrefs: string[];
|
||||
externalLinks: { href: string; rel: string; crossorigin?: string }[];
|
||||
variablesByComp: Record<string, Record<string, unknown>>;
|
||||
}
|
||||
|
||||
@@ -150,7 +150,8 @@ export function inlineSubCompositions(
|
||||
const styles: string[] = [];
|
||||
const scripts: string[] = [];
|
||||
const externalScriptSrcs: string[] = [];
|
||||
const externalLinkHrefs: string[] = [];
|
||||
const externalLinks: { href: string; rel: string; crossorigin?: string }[] = [];
|
||||
const seenLinkHrefs = new Set<string>();
|
||||
const variablesByComp: Record<string, Record<string, unknown>> = {};
|
||||
|
||||
for (const hostEl of hosts) {
|
||||
@@ -227,8 +228,13 @@ export function inlineSubCompositions(
|
||||
...compDoc.head.querySelectorAll('link[rel="stylesheet"], link[rel="preconnect"]'),
|
||||
]) {
|
||||
const href = (link.getAttribute("href") || "").trim();
|
||||
if (href && !externalLinkHrefs.includes(href)) {
|
||||
externalLinkHrefs.push(href);
|
||||
if (href && !seenLinkHrefs.has(href)) {
|
||||
seenLinkHrefs.add(href);
|
||||
const rel = (link.getAttribute("rel") || "").trim();
|
||||
const crossorigin = link.hasAttribute("crossorigin")
|
||||
? link.getAttribute("crossorigin") || ""
|
||||
: undefined;
|
||||
externalLinks.push({ href, rel, crossorigin });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -335,5 +341,5 @@ export function inlineSubCompositions(
|
||||
hostEl.removeAttribute("data-composition-src");
|
||||
}
|
||||
|
||||
return { styles, scripts, externalScriptSrcs, externalLinkHrefs, variablesByComp };
|
||||
return { styles, scripts, externalScriptSrcs, externalLinks, variablesByComp };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user