mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #719] [MERGED] fix(fonts): double-comma syntax error when font options have a trailing comma #797
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#797
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/719
Author: @james-elicx
Created: 3/30/2026
Status: ✅ Merged
Merged: 3/30/2026
Merged by: @james-elicx
Base:
main← Head:james/fonts-fix📝 Commits (1)
12694cdfix(fonts): double-comma syntax error when font options have a trailing comma📊 Changes
2 files changed (+45 additions, -1 deletions)
View changed files
📝
packages/vinext/src/plugins/fonts.ts(+7 -1)📝
tests/font-google.test.ts(+38 -0)📄 Description
Problem
vinext buildfailed with a cryptic[builtin:vite-transform] Error: Unexpected token in app/layout.tsx at 191..192for any project that usednext/font/googlewith trailing-comma style (common with Prettier defaults):The error position and file name were both misleading — the reported byte offset pointed into
function Layoutin the original source, but the actual failure was in the transformed code produced by thevinext:google-fontsVite plugin.Root cause
injectSelfHostedCss(inpackages/vinext/src/plugins/fonts.ts) injects a_selfHostedCSSproperty into the font constructor's options object at build time. It computed the separator before the new property as:This only handled the empty-object case. When the options already had a trailing comma, the trimmed content ended with
,, not{, so it unconditionally prepended,and produced a double comma:Rolldown's
builtin:vite-transformnative plugin then failed to parse this invalid JS, attributing the error to a byte offset in the MagicString sourcemap that mapped back to an unrelated position in the original source file.Fix
Extend the separator check to also skip
,when the content already ends with a trailing comma:Also adds a regression test (
does not produce double-comma when font options have a trailing comma) totests/font-google.test.ts.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.