fix(shadcn): remove unused default Next.js fonts when init replaces them - #11413
Open
bunlongheng wants to merge 1 commit into
Open
fix(shadcn): remove unused default Next.js fonts when init replaces them#11413bunlongheng wants to merge 1 commit into
bunlongheng wants to merge 1 commit into
Conversation
Fixes shadcn-ui#11124 When `shadcn init` applies a preset with a different font, the CLI rewrites the --font-sans theme mapping in globals.css but leaves the default create-next-app Geist import, declaration, and variable usage in layout.tsx. The unused font is still downloaded at runtime. transformLayoutFonts now removes a default font (Geist -> --font-geist-sans, Geist_Mono -> --font-geist-mono) when a registry font takes over the corresponding root slot. The removal is guarded: it only strips .variable className usage and bails out safely if the font is referenced elsewhere (e.g. geistSans.className). Geist_Mono is kept when only --font-sans is replaced. Three new tests added; all 34 existing tests pass.
Contributor
|
@bunlongheng is attempting to deploy a commit to the shadcn-pro Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Can you sign the commits please? See https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits. Thank you. |
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.
Fixes #11124
Problem
When
shadcn initapplies a preset with a different font (e.g. Inter), the CLI rewrites the--font-sanstheme mapping inglobals.cssbut leaves the default create-next-appGeistimport, declaration, andgeistSans.variableclassName usage inlayout.tsx. The unused font is still downloaded at runtime.Fix
transformLayoutFontsnow removes a default font (Geist->--font-geist-sans,Geist_Mono->--font-geist-mono) when a registry font takes over the corresponding root slot (--font-sans/--font-mono):.variableusage from className (template literal,cn(), or bare expression)next/font/googleif no longer usedgeistSans.className)Geist_Monois kept when only--font-sansis replaced, since--font-monostill maps to itTesting
3 new tests covering:
All 34 tests in
update-fonts.test.tspass; no existing test expectations changed.