Skip to content

feat(fonts): getFontBuffer()#15182

Merged
florian-lefebvre merged 20 commits intomainfrom
feat/get-font-buffer
Jan 22, 2026
Merged

feat(fonts): getFontBuffer()#15182
florian-lefebvre merged 20 commits intomainfrom
feat/get-font-buffer

Conversation

@florian-lefebvre
Copy link
Member

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

Changes

  • We have APIs to allow using font data programmatically, which was mainly designed for advanced usage such as OG images
  • However, getting the font buffer has always been clunky. It actually didn't work during prererendering (which is the main usecase)
  • This PR introduces a new getFontBuffer() function that get the buffer using a url from the result of getFontData()
  • In SSR if getFontData() is used, a js file is created per buffer in the server output in addition to actual files in the client output. Not sure there's much we can do about it
  • On the client, calling the function always throws. This is avoid making the client bundle size huge

Testing

  • New unit test
  • Add ssr integrated tests
  • Add integrated tests

Docs

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

changeset-bot bot commented Jan 13, 2026

🦋 Changeset detected

Latest commit: 50eb0a2

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 13, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 13, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing feat/get-font-buffer (50eb0a2) with main (47ae148)1

Summary

✅ 9 untouched benchmarks

Footnotes

  1. No successful run was found on main (dc5bcd9) during the generation of this report, so 47ae148 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@florian-lefebvre florian-lefebvre marked this pull request as ready for review January 21, 2026 14:00
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.

Beautiful changeset @florian-lefebvre ! 🙌

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.

Please make sure that the RFC is updated

@florian-lefebvre florian-lefebvre merged commit cb60ee1 into main Jan 22, 2026
25 of 26 checks passed
@florian-lefebvre florian-lefebvre deleted the feat/get-font-buffer branch January 22, 2026 07:31
@astrobot-houston astrobot-houston mentioned this pull request Jan 22, 2026
dadezzz pushed a commit to dadezzz/ice-notes that referenced this pull request Jan 26, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [astro](https://astro.build) ([source](https://github.com/withastro/astro/tree/HEAD/packages/astro)) | [`5.16.12` → `5.16.13`](https://renovatebot.com/diffs/npm/astro/5.16.12/5.16.13) | ![age](https://developer.mend.io/api/mc/badges/age/npm/astro/5.16.13?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/astro/5.16.12/5.16.13?slim=true) |

---

### Release Notes

<details>
<summary>withastro/astro (astro)</summary>

### [`v5.16.13`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#51613)

[Compare Source](https://github.com/withastro/astro/compare/[email protected]@5.16.13)

##### Patch Changes

- [#&#8203;15182](withastro/astro#15182) [`cb60ee1`](withastro/astro@cb60ee1) Thanks [@&#8203;florian-lefebvre](https://github.com/florian-lefebvre)! - Adds a new `getFontBuffer()` method to retrieve font file buffers when using the experimental Fonts API

  The `getFontData()` helper function from `astro:assets` was introduced in 5.14.0 to provide access to font family data for use outside of Astro. One of the goals of this API was to be able to retrieve buffers using URLs.

  However, it turned out to be impactical and even impossible during prerendering.

  Astro now exports a new `getFontBuffer()` helper function from `astro:assets` to retrieve font file buffers from URL returned by `getFontData()`. For example, when using [satori](https://github.com/vercel/satori) to generate OpenGraph images:

  ```diff
  // src/pages/og.png.ts

  import type{ APIRoute } from "astro"
  -import { getFontData } from "astro:assets"
  +import { getFontData, getFontBuffer } from "astro:assets"
  import satori from "satori"

  export const GET: APIRoute = (context) => {
    const data = getFontData("--font-roboto")

    const svg = await satori(
      <div style={{ color: "black" }}>hello, world</div>,
      {
        width: 600,
        height: 400,
        fonts: [
          {
            name: "Roboto",
  -          data: await fetch(new URL(data[0].src[0].url, context.url.origin)).then(res => res.arrayBuffer()),
  +          data: await getFontBuffer(data[0].src[0].url),
            weight: 400,
            style: "normal",
          },
        ],
      },
    )

    // ...
  }
  ```

  See the [experimental Fonts API documentation](https://docs.astro.build/en/reference/experimental-flags/fonts/#accessing-font-data-programmatically) for more information.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi45Mi40IiwidXBkYXRlZEluVmVyIjoiNDIuOTIuNCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: Renovate Bot <[email protected]>
Co-committed-by: Renovate Bot <[email protected]>
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.

4 participants