Skip to content

fix(module): preload global fonts - #856

Open
Meliceanu wants to merge 1 commit into
nuxt:mainfrom
Meliceanu:fix/preload-global-fonts
Open

fix(module): preload global fonts#856
Meliceanu wants to merge 1 commit into
nuxt:mainfrom
Meliceanu:fix/preload-global-fonts

Conversation

@Meliceanu

Copy link
Copy Markdown

Resolves #834

What

Global fonts (global: true) are never preloaded, even with preload: true set.

Why

The normal font-preload path runs through shouldPreload, which feeds into fontMap and finally into build:manifest. The nuxt-fonts-global.css template, however, only generates the @font-face rule and skips this process entirely, so global fonts never enter the preload map.

How

I extracted shouldPreload into a shared function and collect the top-priority font into fontMap, using the font-family name as the key. This lets build:manifest correctly attach the font to the entry chunk. As a result, global fonts are preloaded as expected.

Testing

I verified the issue is fixed in a production build, and the existing snapshot now includes /font-global.woff2.

@Meliceanu
Meliceanu requested a review from danielroe as a code owner July 14, 2026 09:30
@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/fonts@856

commit: 5540069

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9507d2a4-9dd7-4146-87ea-5de6ef56644d

📥 Commits

Reviewing files that changed from the base of the PR and between 94beea5 and 5540069.

📒 Files selected for processing (2)
  • src/module.ts
  • test/basic.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/basic.test.ts
  • src/module.ts

📝 Walkthrough

Walkthrough

Global font processing now determines preload eligibility through a shared shouldPreload helper, selects the highest-priority font per family, and records eligible font URLs in the shared fontMap. The helper is passed to FontFamilyInjectionPlugin, and the feature test snapshot now includes /font-global.woff2 among the generated preload links.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preloading global fonts.
Description check ✅ Passed The description is directly about fixing global font preloading and matches the changes.
Linked Issues check ✅ Passed The changes address #834 by adding preload handling for global fonts so preload links can be generated.
Out of Scope Changes check ✅ Passed The diff stays focused on global font preload handling and the related test snapshot update.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Meliceanu

Copy link
Copy Markdown
Author

The failing ci (ubuntu-latest) job looks unrelated to this PR. It's a flaky test download, not related to the changes.

test/base-url.test.ts fails during the fixture build while src/assets.ts downloads a stubbed Adobe font, and the font that 404s differs between runs (aleo-i4.woff2, then barlow-n4.woff2) with no code change in between. Windows passes. This PR only touches the preload map in src/module.ts and doesn't change which fonts get downloaded.

@Meliceanu
Meliceanu force-pushed the fix/preload-global-fonts branch from 9325c84 to 5540069 Compare July 20, 2026 07:38
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 69.40%. Comparing base (16e87f6) to head (5540069).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/module.ts 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #856      +/-   ##
==========================================
+ Coverage   68.01%   69.40%   +1.39%     
==========================================
  Files           9        9              
  Lines         297      304       +7     
  Branches       67       71       +4     
==========================================
+ Hits          202      211       +9     
+ Misses         78       77       -1     
+ Partials       17       16       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Meliceanu

Copy link
Copy Markdown
Author

Additional checks needed or all good? @danielroe

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.

preload option doesn't add <link> tags to <head>

2 participants