fix(cloudflare): resolve fonts via localFetch when ASSETS binding unavailable#527
Merged
fix(cloudflare): resolve fonts via localFetch when ASSETS binding unavailable#527
Conversation
…vailable On Cloudflare Workers with Workers Static Assets (WSA), the ASSETS service binding is not injected into the worker's env object. Static assets are served at the runtime level before the worker's fetch runs, so env.ASSETS is undefined. The previous fallback used event.$fetch (ofetch) which routes through Nitro's external HTTP path and cannot serve public assets, returning 404 for font files. This caused all fonts to fail loading, resulting in blank OG images with no visible text. Replace the event.$fetch fallback with event.fetch (Nitro localFetch) which routes through the h3 app including Nitro's built-in public asset handler. This correctly resolves fonts from the asset manifest. Closes #523
When preferStatic is set (Takumi), the font loader was using satoriSrc which points to .woff files downloaded by fontless for Satori. Takumi only supports .ttf and .woff2, so these .woff files loaded successfully but failed at render time with "Unsupported font format". Now only uses satoriSrc when it's a format Takumi can parse (.ttf), otherwise falls through to the original .woff2 which Takumi handles natively.
…mats
Replace the boolean `supportsWoff2` and `preferStatic` options with a
single `supportedFormats` set that explicitly declares which font
formats each renderer can parse:
Satori: ttf, woff (cannot parse WOFF2)
Takumi: ttf, woff2 (cannot parse WOFF)
This eliminates .woff fonts being loaded and rejected by Takumi at
render time ("Unsupported font format" warnings), and removes the
`preferStatic` workaround which was causing Takumi to use .woff
satoriSrc files it couldn't parse.
Also gates fontless downloads (WOFF2 → static TTF/WOFF conversion)
on hasSatoriRenderer() only, since Takumi handles WOFF2 natively
and doesn't need fontless alternatives. This reduces build time and
output size for Takumi-only projects.
Satori supports TTF, OTF, and WOFF. The previous commit missed OTF.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
Closes #523
❓ Type of change
📚 Description
On Cloudflare Workers with Workers Static Assets (WSA), the
ASSETSservice binding is not injected into the worker'senvobject. Static assets are served at the Cloudflare runtime level before the worker'sfetchruns, soenv.ASSETSisundefined. This differs from Cloudflare Pages whereASSETSis always present inenv.The previous fallback used
event.$fetch(ofetch) which cannot serve public assets on CF Workers, returning 404 for all font files. This caused blank OG images with no visible text.Replaces the
event.$fetchfallback withevent.fetch(NitrolocalFetch) which routes through the h3 app and Nitro's built-in public asset handler, correctly resolving fonts from the asset manifest.Reproduction: Clone https://github.com/yusufalitangoz/nuxt-4-shadcn-boilerplate, build with
NITRO_PRESET=cloudflare_module, run withwrangler dev. OG images render blank. With this fix, fonts load and text appears.