Repository navigation
Load font paths from disk in Bun - #1576
Merged
Merged
Conversation
Bun defines `self` on its main thread, without a `document`, so the loaders' web worker check (`typeof self !== "undefined" && self.document === undefined`) took Bun for a worker. loadTTF and loadFont then passed a file path to fetch, which fails with "fetch() URL is invalid", though the README says they run in Bun. Check for WorkerGlobalScope instead, which browser workers have and Bun's and Deno's main threads don't. The check lives in runtime.ts, shared by loadTTF, loadFont and the bitmap font parser. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
🚀 PR was released in |
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.
Load font paths from disk in Bun
In Bun,
loadTTF("fonts/Inter-Regular.otf")fails withloadTTF: couldn't fetch "...": fetch() URL is invalid, though the README says@jimp/layoutandloadTTFrun in Bun.loadFontfails the same way for a.fntpath.The loaders decide between reading from disk and
fetchwithisWebWorker = typeof self !== "undefined" && self.document === undefined. Bun definesselfon its main thread, without adocument, so it looks like a web worker and the path goes tofetch. Deno's main thread has the sameself.isWebWorkernow checks forWorkerGlobalScope, which browser workers have and Bun's and Deno's main threads don't. It lives in a newruntime.ts, shared byloadTTF,loadFontand the bitmap font parser (which had two copies of the old check). Node and browser main threads behave as before: they never had aselfwithout awindow.runtime.node.test.tsstubs a globalselfthe way Bun has it, then checks thatisWebWorkeris false and thatloadTTFandloadFontread paths from disk. Onmainall three tests fail, with the samefetcherror.Validation on macOS, Node 24.15:
dist,loadTTFandloadFontload fonts by path in Bun 1.3.9 and Node.Not tested: Deno end to end (from outside a project it stops earlier, at
import("opentype.js")), a real browser web worker, and the full workspace test run.🤖 Generated with Claude Code