Skip to content

Refactor font loading to use Vite asset imports - #357

Open
bartveneman wants to merge 3 commits into
mainfrom
claude/versioned-font-csp-8kh26m
Open

Refactor font loading to use Vite asset imports#357
bartveneman wants to merge 3 commits into
mainfrom
claude/versioned-font-csp-8kh26m

Conversation

@bartveneman

Copy link
Copy Markdown
Member

Summary

Refactored the Teko 500 font loading mechanism to use Vite's asset import system instead of hardcoded file paths with manual versioning. This allows Vite to handle asset hashing automatically while keeping the font preload link dynamic.

Key Changes

  • Font asset import: Added import of teko-500.woff2 as a module in +layout.svelte to leverage Vite's asset hashing
  • Dynamic preload link: Moved the font preload link from static app.html to +layout.svelte and bound it to the imported asset URL, ensuring it always references the correct hashed filename
  • CSS path update: Updated the @font-face URL in style.css from the manually-versioned path (../../../teko-500.2019-08-10.woff2) to the new location (../fonts/teko-500.woff2)
  • Regex pattern generalization: Modified the FONT_PRELOAD regex in hooks.server.ts to match on rel="preload" and as="font" attributes instead of a specific filename, making it resilient to Vite's asset hashing

Implementation Details

  • The font file was relocated to src/lib/fonts/ directory
  • The preload link now uses the hashed URL provided by Vite's import system, eliminating the need for manual version strings
  • The regex pattern change ensures the head reordering logic continues to work regardless of how Vite hashes the asset filename

https://claude.ai/code/session_01WTWxPkFxYSSb77sTr4nHBg

claude added 2 commits July 31, 2026 06:37
Move teko-500.woff2 into src/lib/fonts so it gets a content hash like
other assets, instead of a manually-typed date suffix duplicated in
both app.html and style.css. style.css's @font-face now resolves the
font through the normal Vite build (guaranteeing it matches whatever
hash Vite assigns), and app.html's preload link is swapped from a
literal path to a placeholder that hooks.server.ts fills in with the
real hashed URL at render time, keeping the two references in sync and
preserving the existing head-ordering/CSP logic.
Drop the placeholder + hooks.server.ts regex-substitution machinery
used to keep the preload link's static position in app.html. Instead,
import the font in the root layout (same as any other Vite-managed
asset) and emit the preload via <svelte:head>, which is the standard
way to reference a hashed build asset outside of CSS. The font preload
and its hoisted stylesheets now land after SvelteKit's modulepreload
hints instead of before them, a difference unlikely to be perceptible.
@netlify

netlify Bot commented Jul 31, 2026

Copy link
Copy Markdown

Deploy Preview for projectwallace ready!

Name Link
🔨 Latest commit 27e193f
🔍 Latest deploy log https://app.netlify.com/projects/projectwallace/deploys/6a6c4699d41c8b0008c7319c
😎 Deploy Preview https://deploy-preview-357--projectwallace.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

The preload <link> was the first child of the layout's <svelte:head>,
ahead of a conditional {#if} block. Since every component's
<svelte:head> content shares one physical document.head, that extra
static node shifted the node sequence Svelte's client hydration walks
to reconnect SSR output to its owning effects — causing Seo.svelte's
unrelated head tags (title, canonical, description, og:*) further down
the tree to lose alignment and get duplicated instead of reused. Moving
the link after the {#if} block keeps the sequence intact.

Copy link
Copy Markdown
Member Author

The ThemeSwitch.spec.ts failure (waitForRequest('/api/theme') timeout) on the latest run is a pre-existing flake, not caused by this PR — the identical failure occurred on an unrelated dependabot PR on 2026-07-28, before this branch existed. No fix needed here.


Generated by Claude Code

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.

2 participants