Skip to content

perf: stop the web-font swap from shifting prerendered text - #17

Merged
spin311 merged 1 commit into
mainfrom
fix/header-font-shift
Nov 26, 2026
Merged

spin311 merged 1 commit into
mainfrom
fix/header-font-shift

Conversation

@spin311

@spin311 spin311 commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Summary

After #16 the pages paint before the web fonts arrive. Lighthouse on the live home page showed CLS 0.043 (mobile), and on a throttled phone it reached 0.04 to 0.08 depending on width. The cause is the Poppins and Kay Pho Du font-display: swap: text laid out while a font was still pending wrapped differently once it settled. Your name flipped from two lines to one at 360 px, the stack line at 412 px, the role line at 1024 px. With every @font-face removed the shift is 0 at all widths, so it is the swap itself, not the fallback faces.

Changes

  • src/fonts.css replaces the @fontsource CSS imports with the site's own rules, for the Latin and Latin Extended subsets only.
    • Poppins (all body text): font-display: optional. The page never re-lays out text for it.
    • Kay Pho Du (the name and page titles): keeps swap, so the name always ends up in its own font.
  • index.html also preloads the two Latin Extended files (5.6 KB and 1.4 KB). "Košarica" and the Slovenian pages use them, and a miss would show "š" in the fallback mid-word.
  • Header.css: the home page name can't wrap (.name:not(.md-text), nowrap). On phones it is min(3rem, 14vw), so it fits at 320 px. Extension titles still wrap.

Trade-off

On a slow connection (Lighthouse's slow-4G profile), Poppins misses the optional window. That visit keeps the size-matched Arial fallback, and the next full page load uses the cached font. On Wi-Fi and fast 4G, Poppins renders on the first visit (checked with CDP getPlatformFontsForNode). The name always renders in Kay Pho Du.

Verified

  • Slow 4G with a 4x CPU throttle, CLS at most 0.0002:
    • home at 320, 360, 390, 412, 768, 1024 and 1366 px (EN), and at 360 and 412 px (SL);
    • the extension pages and donate at 360–412 px (re-checked on this deploy preview).
  • No horizontal scroll.
  • lint, tsc, check-translations, check-netlify-routes, check-sitemap and build pass.

Poppins becomes font-display: optional, from the site's own @font-face rules (the
@fontsource CSS hard-codes swap), and all four subsets are preloaded. Kay Pho Du keeps
swap so the name always ends up in its font; the home page name can't wrap any more,
so the swap can't change its line count. CLS on slow 4G: 0.04-0.08 before, at most
0.0002 after, at 320-1366 px in both languages.
@netlify

netlify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for rainbow-halva-839807 ready!

Name Link
🔨 Latest commit 666862c
🔍 Latest deploy log https://app.netlify.com/projects/rainbow-halva-839807/deploys/6b086a5ed6f7cd47b6461ebf
😎 Deploy Preview https://deploy-preview-17--rainbow-halva-839807.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@spin311
spin311 merged commit 0b0746e into main Nov 26, 2026
5 checks passed
@spin311
spin311 deleted the fix/header-font-shift branch November 26, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant