Skip to content

Commit aa33012

Browse files
committed
fix(fonts): skip fontaine fallbacks
1 parent 82cec81 commit aa33012

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/build/css/css-utils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,12 +739,22 @@ function isSystemFont(name: string): boolean {
739739
return name.startsWith('-') || name.startsWith('var(')
740740
}
741741

742+
// fontaine/@nuxt/fonts emit metric-only fallback @font-face entries named
743+
// "<Family> fallback" (e.g. "Sofia Pro fallback") backed by local() Arial/Times.
744+
// They exist purely to reduce CLS in the browser and are not real downloadable
745+
// fonts, so OG renderers must not try to resolve them via fontless providers.
746+
const RE_FONTAINE_FALLBACK = / fallback$/i
747+
748+
function isFontaineFallback(name: string): boolean {
749+
return RE_FONTAINE_FALLBACK.test(name)
750+
}
751+
742752
export function extractCustomFontFamilies(cssValue: string): string[] {
743753
return cssValue
744754
.replace(RE_IMPORTANT, '')
745755
.split(',')
746756
.map(p => p.trim().replace(RE_QUOTES, ''))
747-
.filter(name => name && !GENERIC_FONT_FAMILIES.has(name.toLowerCase()) && !RE_ONLY_DIGITS.test(name) && !isSystemFont(name))
757+
.filter(name => name && !GENERIC_FONT_FAMILIES.has(name.toLowerCase()) && !RE_ONLY_DIGITS.test(name) && !isSystemFont(name) && !isFontaineFallback(name))
748758
}
749759

750760
// ============================================================================

src/build/fontless.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,13 +626,17 @@ export async function resolveOgImageFonts(options: {
626626
const coveredFamilies = new Set(allFonts.map(f => f.family))
627627
let missingFamilies: string[] = []
628628

629+
// Skip fontaine-generated metric fallbacks ("<Family> fallback") — they're
630+
// local() metric shims for CLS, not real downloadable fonts.
631+
const isFontaineFallback = (name: string): boolean => / fallback$/i.test(name)
632+
629633
if (fontRequirements.families.length > 0) {
630-
missingFamilies = fontRequirements.families.filter(f => !coveredFamilies.has(f))
634+
missingFamilies = fontRequirements.families.filter(f => !coveredFamilies.has(f) && !isFontaineFallback(f))
631635
}
632636
else {
633637
const defaultVar = tw4FontVars['font-sans']
634638
if (defaultVar)
635-
missingFamilies = extractCustomFontFamilies(defaultVar).filter(f => !coveredFamilies.has(f))
639+
missingFamilies = extractCustomFontFamilies(defaultVar).filter(f => !coveredFamilies.has(f) && !isFontaineFallback(f))
636640
}
637641

638642
if (missingFamilies.length > 0) {

0 commit comments

Comments
 (0)