Skip to content

feat(fonts)!: local provider unification#15213

Merged
florian-lefebvre merged 165 commits intomainfrom
feat/fonts-local-provider-unification
Jan 22, 2026
Merged

feat(fonts)!: local provider unification#15213
florian-lefebvre merged 165 commits intomainfrom
feat/fonts-local-provider-unification

Conversation

@florian-lefebvre
Copy link
Member

@florian-lefebvre florian-lefebvre commented Jan 15, 2026

Changes

  • Depends on feat(fonts)!: family options #15175
  • Updates the local provider to be a regular provider (see changeset for change), consistency FTW! This allows to simplify code and docs by a lot
  • I used it as an opportunity to simplify fonts internals, thanks to the learnings of when we coded with Joe Rainsberger in December. I know the diff is massive so really it's not worth reviewing (altho it's doable), as long as the tests pass we're safe
  • TLDR: unified API for font providers, removed some internal abstractions, more tests!

Testing

  • Added a lot more tests for the core logic
  • Added tests for some infra
  • Added in memory e2e tests
  • All other tests should pass

Docs

@florian-lefebvre florian-lefebvre self-assigned this Jan 15, 2026
@changeset-bot
Copy link

changeset-bot bot commented Jan 15, 2026

🦋 Changeset detected

Latest commit: f806926

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jan 15, 2026
Base automatically changed from feat/fonts-family-options to main January 21, 2026 13:18
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 21, 2026

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing feat/fonts-local-provider-unification (a7ac252) with main (edabeaa)

Open in CodSpeed

@florian-lefebvre florian-lefebvre marked this pull request as ready for review January 22, 2026 09:57
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

There's a lot of code moved around, and I didn't have a chance to look all of it. If the tests pass (which are a lot), happy to merge it. Please update the RFC (didn't see it mentioned in the PR)

name: "Custom",
cssVariable: "--font-custom",
- provider: "local",
+ provider: fontProviders.local(),
Copy link
Member

Choose a reason for hiding this comment

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

I like the new API

Comment on lines +30 to +33
// The index keeps track of encountered URLs. We can't use a regular for loop
// below because it may contain sources without urls, which would prevent preloading completely
let index = 0;
for (const source of font.src) {
Copy link
Member

Choose a reason for hiding this comment

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

Based on the comment, Can't we use a filter before this loop?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could but I think that would be a bit less efficient? Like require 2 loops instead of 1

@florian-lefebvre
Copy link
Member Author

@ematipico sorry again for the huge diff, I know it's not great. I had updated the RFC before requesting a review

@florian-lefebvre florian-lefebvre merged commit c775fce into main Jan 22, 2026
46 of 48 checks passed
@florian-lefebvre florian-lefebvre deleted the feat/fonts-local-provider-unification branch January 22, 2026 16:40
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

I can't believe this is the LAST. EXPERIMENTAL. FONTS. PR. @florian-lefebvre 🥳

Nice work, just some very small comments from me here, and the docs PR is good to go with one tiny nit!


Previously, there were 2 kinds of font providers: remote and local.

Font providers are now unified. If you are using the local provider, here is how you can update:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Font providers are now unified. If you are using the local provider, here is how you can update:
Font providers are now unified. If you are using the local provider, the process for configuring local fonts must be updated:

}]
}
});
```
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
```
```
Once configured, there is no change to using local fonts in your project. However, you should inspect your deployed site to confirm that your new font configuration is being applied.
See [the experimental Fonts API docs](https://docs.astro.build/en/reference/experimental-flags/fonts/) for more information.
`````


Exposes `root` on `FontProvider` `init()` context

When building a `FontProvider` for the experimental Fonts API, the `init()` method receives a `context`. This context now exposes a `root` URL, useful for resolving local files:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
When building a `FontProvider` for the experimental Fonts API, the `init()` method receives a `context`. This context now exposes a `root` URL, useful for resolving local files:
When building a custom `FontProvider` for the experimental Fonts API, the `init()` method receives a `context`. This context now exposes a `root` URL, useful for resolving local files:

I think this helps people quickly grok "Oh, I'm not building my own font provider... I can ignore!" (Assuming that's the intention)

title: 'Font buffer not found',
message: (url: string) =>
`No buffer was found for the \`"${url}"\` passed to the \`getFontBuffer()\` function.`,
`No buffer was found for the \`"${url}"\` url passed to the \`getFontBuffer()\` function.`,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`No buffer was found for the \`"${url}"\` url passed to the \`getFontBuffer()\` function.`,
`No buffer was found for the \`"${url}"\` URL passed to the \`getFontBuffer()\` function.`,

If this is just regular paragraph text, then URL is upper cased. (If you want to describe an API's option, I'd use url inline code syntax.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs pr pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants