Skip to content

Commit f37a6f7

Browse files
committed
fix(producer): address font deduplication review
1 parent 439b5ff commit f37a6f7

6 files changed

Lines changed: 12 additions & 14 deletions

File tree

‎docs/guides/troubleshooting.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ npx hyperframes render --docker --output output.mp4
219219

220220
The render compiler removes equivalent top-level `@font-face` declarations from active, unconditional styles before embedding local font files. The last equivalent declaration stays in place, preserving its order relative to other font faces. Conditional rules and alternate styles are retained. Source scene files are unchanged.
221221

222+
Only identical declarations with the same family, `src`, and descriptors are merged. If the export is still large, make repeated scene font rules match exactly or declare them once in a shared root style.
223+
222224
### Every render takes about 45 seconds longer than expected
223225

224226
A composition that never registers a GSAP timeline still makes the producer wait

‎packages/core/src/compiler/htmlBundler.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
compositionStyle,
44
cssStyleMergeKey,
55
deferScriptsUntilFonts,
6-
UNCONDITIONAL_CSS_KEY,
6+
isAlwaysAppliedStyle,
77
headStyleRuns,
88
INLINED_FILE_ATTR,
99
inlineScriptRuns,
@@ -725,10 +725,6 @@ function placeSceneStylesLikeRender(document: Document): void {
725725
first.before(holder);
726726
}
727727

728-
function isAlwaysAppliedStyle(el: Element): boolean {
729-
return cssStyleMergeKey(el) === UNCONDITIONAL_CSS_KEY && !el.closest("template, noscript, svg");
730-
}
731-
732728
type PartRun<T> = { scene?: string; chunks: T[] };
733729

734730
function pushRun<T>(runs: PartRun<T>[], scene: string | undefined, chunk: T): void {

‎packages/core/src/compiler/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export {
6868
AFTER_FONTS_SCRIPT_TYPE,
6969
compositionStyle,
7070
cssStyleMergeKey,
71-
UNCONDITIONAL_CSS_KEY,
71+
isAlwaysAppliedStyle,
7272
deferScriptsUntilFonts,
7373
headStyleRuns,
7474
inlineScriptRuns,

‎packages/core/src/compiler/scriptRuns.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ export function cssStyleMergeKey(el: Element): string | undefined {
120120
return JSON.stringify([media === "all" ? "" : media, el.getAttribute("title") ?? ""]);
121121
}
122122

123-
export const UNCONDITIONAL_CSS_KEY = JSON.stringify(["", ""]);
123+
const UNCONDITIONAL_CSS_KEY = JSON.stringify(["", ""]);
124+
125+
export function isAlwaysAppliedStyle(el: Element): boolean {
126+
return cssStyleMergeKey(el) === UNCONDITIONAL_CSS_KEY && !el.closest("template, noscript, svg");
127+
}
124128

125129
/** A link's identity and condition; fetch attributes (crossorigin, integrity, referrerpolicy) are not compared. */
126130
function linkDedupeKey(el: Element): string {

‎packages/producer/src/services/htmlCompiler.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ import {
5656
readDeclaredDefaults,
5757
parseHostVariableValues,
5858
headStyleRuns,
59-
cssStyleMergeKey,
60-
UNCONDITIONAL_CSS_KEY,
59+
isAlwaysAppliedStyle,
6160
dedupeFontFaceRules,
6261
inlineScriptRuns,
6362
parsesAsScript,
@@ -942,10 +941,7 @@ function coalesceHeadStylesAndBodyScripts(html: string): string {
942941
const body = document.querySelector("body");
943942
if (!head && !body) return html;
944943

945-
const liveStyles = [...document.querySelectorAll("style")].filter(
946-
(el) =>
947-
cssStyleMergeKey(el) === UNCONDITIONAL_CSS_KEY && !el.closest("template, noscript, svg"),
948-
);
944+
const liveStyles = [...document.querySelectorAll("style")].filter(isAlwaysAppliedStyle);
949945
const dedupedStyles = dedupeFontFaceRules(liveStyles.map((el) => el.textContent || ""));
950946
liveStyles.forEach((el, i) => {
951947
el.textContent = dedupedStyles[i] ?? "";

‎scripts/package-size-budgets.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"@hyperframes/producer": {
3939
"packed": 828932,
40-
"unpacked": 2840135
40+
"unpacked": 3012450
4141
},
4242
"@hyperframes/sdk": {
4343
"packed": 90662,

0 commit comments

Comments
 (0)