Skip to content

fix(module): preload global fonts#856

Open
Meliceanu wants to merge 2 commits into
nuxt:mainfrom
Meliceanu:fix/preload-global-fonts
Open

fix(module): preload global fonts#856
Meliceanu wants to merge 2 commits 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: 9325c84

@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: 6b0d8849-91c7-419e-b4e3-3722129d7d73

📥 Commits

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

📒 Files selected for processing (2)
  • src/module.ts
  • test/basic.test.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 states the main change: preloading global fonts.
Description check ✅ Passed The description matches the code changes and explains the global-font preload fix.
Linked Issues check ✅ Passed The PR addresses issue #834 by adding preload links for the affected global fonts.
Out of Scope Changes check ✅ Passed The changes stay focused on global font preloading and the corresponding 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.

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>

1 participant