Skip to content

fix(font): retry font load after a failed fetch - #3568

Open
mskec wants to merge 1 commit into
diegomura:masterfrom
mskec:font-fetch-rejection-cached
Open

mskec wants to merge 1 commit into
diegomura:masterfrom
mskec:font-fetch-rejection-cached

Conversation

@mskec

@mskec mskec commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

What

FontSource.load() keeps the first _load() promise in a cache. If that call fails, the rejected promise stays in the cache. Every later load() call returns the same rejection. The font never loads again.

This problem is if this happens in a long running container. One failed fetch then breaks each later render that uses the font.

Reproduction

Register a font. Make the first fetch call fail. Render two documents that use the font.

let failNext = true;
const realFetch = globalThis.fetch;
globalThis.fetch = (...args) =>
  failNext
    ? ((failNext = false), Promise.reject(new TypeError('fetch failed')))
    : realFetch(...args);

Font.register({ family: 'Roboto', src: 'https://example.com/Roboto.ttf' });

await renderToBuffer(doc()); // fails, as expected
await renderToBuffer(doc()); // fails, but must succeed

The second render fails with the error from the first render. No second fetch occurs.

Fix

load() removes the cached promise when _load() fails, then re-throws the error. The cache keeps only a successful load.

@changeset-bot

changeset-bot Bot commented Sep 16, 2026

Copy link
Copy Markdown

馃 Changeset detected

Latest commit: 13f0242

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

This PR includes changesets to release 11 packages
Name Type
@react-pdf/font Patch
@react-pdf/renderer Patch
@react-pdf/types Patch
@react-pdf/math Patch
@react-pdf/mermaid Patch
@react-pdf/ui Patch
@react-pdf/examples Patch
@react-pdf/layout Patch
@react-pdf/render Patch
@react-pdf/stylesheet Patch
@react-pdf/tailwind Patch

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

@vercel

vercel Bot commented Sep 16, 2026

Copy link
Copy Markdown

@mskec is attempting to deploy a commit to the diegomura Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

1 participant