Fix Turbopack compatibility: use asset URL pattern for font#69
Open
vladmdgolam wants to merge 1 commit intoutsuboco:mainfrom
Open
Fix Turbopack compatibility: use asset URL pattern for font#69vladmdgolam wants to merge 1 commit intoutsuboco:mainfrom
vladmdgolam wants to merge 1 commit intoutsuboco:mainfrom
Conversation
8096568 to
85cdbf4
Compare
Use standard asset URL pattern (new URL('./roboto.woff', import.meta.url).href)
instead of direct .woff import. This avoids Turbopack incorrectly trying to
parse the binary font file as UTF-8 JavaScript.
Changes:
- Add src/roboto-font.ts exporting font via URL API
- Update TextsHighHZ.tsx to use new font module
- Remove *.woff module declaration (no longer needed since we're not
directly importing .woff files anymore)
Fixes: utsuboco#59, utsuboco#66
85cdbf4 to
1c5a2da
Compare
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.
Problem
When using r3f-perf with Next.js + Turbopack, the build fails with:
This happens because the original
import font from './roboto.woff'causes Turbopack to try parsing the binary font file as UTF-8 JavaScript.Relates to #59 and #66.
Solution
Use the standard asset URL pattern that all modern bundlers recognize:
This pattern works with Turbopack, webpack 5, and Vite — they resolve the
.wofffile, copy it to the output, and provide a proper URL at runtime.Changes
src/roboto-font.ts(new) — exports font usingnew URL()patternsrc/components/TextsHighHZ.tsx— imports from../roboto-fontinstead of../roboto.woffsrc/globals.d.ts— removeddeclare module '*.woff'(no longer needed since we're not importing.wofffiles directly)3 files changed, 8 insertions(+), 3 deletions(-)
Why this pattern?
troika-three-text (used by drei's
<Text>) loads fonts via a web worker with an opaque origin. Thenew URL()pattern ensures the font is accessible via HTTP URL, which works in all environments including web workers.Test plan
pnpm run buildsucceeds