Skip to content

Conversation

hi-ogawa
Copy link
Collaborator

@hi-ogawa hi-ogawa commented Sep 28, 2025

This PR updated preload option to support selecting preloaded fonts by preload.subsets: [...].

It also updated a public API transformCss to have more flexible preload selection. I added FontFamilyInjectionPluginOptions.filterFontsToPreload and deprecated FontFamilyInjectionPluginOptions.shouldPreload.

Copy link

netlify bot commented Sep 28, 2025

Deploy Preview for fontless failed.

Name Link
🔨 Latest commit 12276c7
🔍 Latest deploy log https://app.netlify.com/projects/fontless/deploys/68db32eae451230008cd57d2

Copy link

codecov bot commented Sep 28, 2025

Codecov Report

❌ Patch coverage is 28.57143% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.79%. Comparing base (d66809d) to head (12276c7).

Files with missing lines Patch % Lines
packages/fontless/src/vite.ts 0.00% 13 Missing ⚠️
packages/fontless/src/utils.ts 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #655      +/-   ##
==========================================
- Coverage   53.40%   52.79%   -0.62%     
==========================================
  Files          11       11              
  Lines         734      752      +18     
  Branches       93       94       +1     
==========================================
+ Hits          392      397       +5     
- Misses        342      355      +13     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link

pkg-pr-new bot commented Sep 28, 2025

Open in StackBlitz

npm i https://pkg.pr.new/fontaine@655
npm i https://pkg.pr.new/fontless@655

commit: 12276c7

@hi-ogawa hi-ogawa marked this pull request as ready for review September 28, 2025 07:58
@hi-ogawa hi-ogawa requested a review from danielroe as a code owner September 28, 2025 07:58
@hi-ogawa hi-ogawa changed the title feat(fontless): support preload by subsets feat(fontless): support selecting preloaded fonts by subsets Sep 28, 2025
* @default false
* @example { subsets: ['latin'] }
*/
type PreloadOption = boolean | { subsets: string[] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might also want to choose preload based on font file extensions (defaulting to only .woff2). maybe we could support just passing a function directly? e.g. preload?: boolean | ((fontFamily: string, data: FontFaceData) => boolean)

Copy link
Collaborator Author

@hi-ogawa hi-ogawa Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, making it more flexible sounds good to me, but my intention was that subsets based preload selection should provide optional most of the case, so simple option preload.subset might be good enough to start with. Btw, woff (meta.priority = 1) returned by google provider is not a subsetted font, which is why it's large and thus they don't get included in current preload.subsets.

That said, I was also thinking that maybe we can later expand option to { subsets: string[], weights: string[], etc. }, which may become tricky, so I agree with exposing boolean function. However, I think we should also keep simple preload.subsets option.

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.

[fontless] support selecting preloaded fonts by subsets

2 participants