Prevent ligature FOUC in self-hosted Material icon fonts by setting font-display: block#22
Prevent ligature FOUC in self-hosted Material icon fonts by setting font-display: block#22
font-display: block#22Conversation
Agent-Logs-Url: https://github.com/MudBlazor/MudBlazor.Icons/sessions/5078d5bb-1efd-41fd-b67a-888a5c12bea3 Co-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>
|
Did not fix it for me in the repro, tho ig it makes sense to have it as block? Idk why google just mentions it in the alert block, rather than just include it by default |
|
The repros ([1], [2]) both point to a general ligature-font loading issue and not primarily a
Google says For MauiAppMaterialSymbolsIconsFlicker: Add a preload for the exact font you use: <link rel="preload"
href="_content/MudBlazor.FontIcons.MaterialSymbols/font/MaterialSymbolsRounded.woff2"
as="font"
type="font/woff2"
crossorigin>Or hide those icons until the font is confirmed loaded, using the CSS Font Loading API: <style>
html.ms-icons-loading .material-symbols-rounded { visibility: hidden; }
</style>
<script>
document.documentElement.classList.add('ms-icons-loading');
(async () => {
try {
await document.fonts.load("74px 'Material Symbols Rounded'", "weight");
await document.fonts.ready;
} finally {
document.documentElement.classList.remove('ms-icons-loading');
}
})();
</script>If the requirement is “never show readable ligature text”, the robust app-level answer is SVG for above-the-fold icons. Preload/gating can reduce the issue, but SVG removes the font-loading dependency. For MudBlazor.Icons:
For MudBlazor:
|
MudBlazor font icons render ligature text in markup, so first paint can show raw text until the icon font is available. Our self-hosted Material Symbols/Icons CSS did not set
font-display, allowing visible text→glyph swaps on initial load (especially with larger Symbols fonts).For Material Symbols, Google’s guidance says to use
display=blockto prevent ligature FOUC.What changed
font-display: block;to every@font-facein both icon packs:src/MudBlazor.FontIcons.MaterialSymbols/wwwroot/css/font.csssrc/MudBlazor.FontIcons.MaterialSymbols/wwwroot/css/font.min.csssrc/MudBlazor.FontIcons.MaterialIcons/wwwroot/css/font.csssrc/MudBlazor.FontIcons.MaterialIcons/wwwroot/css/font.min.cssScope
.mud-icon-rootoverflow rule).Example (
@font-face)Closes #17, Closes MudBlazor/MudBlazor#13028