Next/Font/Google: Missing Fallback Metrics For Renamed 'Montserrat Underline' Causes 'Failed To Find Font Override Values'
When using `Montserrat_Underline` from `next/font/google` with default `adjustFontFallback`, Next.js logs 'Failed to find font override values' because the bundled Capsize metrics file uses the old family name 'Montserrat Subrayada' while the font catalog uses the new name 'Montserrat Underline'. The font itself still downloads and renders, but fallback adjustment metrics are unavailable, causing error noise and potential layout shift.
In `next/dist/server/font-utils.js`, `calculateSizeAdjustValues` formats the font family to camelCase (`montserratUnderline`) and looks it up in `capsize-font-metrics.json`. That JSON only contains `montserratSubrayada` (old name), so the lookup returns `undefined`. The subsequent destructuring throws, which is caught in `get-fallback-font-override-metrics.js` and logged as 'Failed to find font override values'.
1. Create a Next.js app using `next/font/google` with `Montserrat_Underline` and default `adjustFontFallback` (i.e., do not set it to false). 2. Run `next dev` or `next build`. 3. Observe the console error: 'Failed to find font override values for font `Montserrat Underline`'.
Fixing Code Block
// Replace the existing calculateSizeAdjustValues function in next/dist/server/font-utils.js
// with this patched version that aliases missing renamed-font metric keys.
function calculateSizeAdjustValues(fontName) {
const fontKey = formatName(fontName);
// Known aliases for Google Fonts families that were renamed after Capsize metrics were generated
const fontKeyAliases = {
montserratUnderline: 'montserratSubrayada'
};
const resolvedKey = fontKeyAliases[fontKey] || fontKey;
const fontMetrics = capsizeFontsMetrics[resolvedKey];
if (!fontMetrics) {
throw new Error(
`Font metrics not found for ${fontName}. Please update capsize-font-metrics.json or set adjustFontFallback: false.`
);
}
const { category, ascent, descent, lineGap, unitsPerEm, xWidthAvg } = fontMetrics;
const fallbackFont =
category === 'serif' ? 'Times New Roman' :
category === 'monospace' ? 'Courier New' :
'Arial';
const sizeAdjust = xWidthAvg ? xWidthAvg / unitsPerEm : undefined;
return {
ascent,
descent,
lineGap,
fallbackFont,
sizeAdjust
};
}
The patch adds a lightweight alias map inside `calculateSizeAdjustValues`. Before looking up the formatted font key in `capsizeFontsMetrics`, it checks if the key has a known alias (here `montserratUnderline` → `montserratSubrayada`). If found, it uses the pre-existing metrics for the old name. This prevents `undefined` destructuring and allows fallback adjustment to work for the renamed font. The change is non-destructive: only adds a mapping, does not remove or modify any existing behavior.
Edge Case Audit
This manual patch will be lost on the next `npm install` or upgrade of `next`. Use `patch-package` to persist it or wait for an official Next.js release. The alias only covers Montserrat Underline; other renamed Google Fonts may require similar entries. If the metrics for `montserratSubrayada` differ from the new font's actual metrics, the fallback adjustment might be slightly off, so verify visual rendering. Rollback: remove the added alias map or revert the file; alternatively set `adjustFontFallback: false` in the font import until upstream fixes the data. No concurrency or multi-threaded issues are introduced because the function is pure and the alias map is static.