Skip to content

fix(shadcn): remove unused default Next.js fonts when init replaces them - #11413

Open
bunlongheng wants to merge 1 commit into
shadcn-ui:mainfrom
bunlongheng:fix/11124-remove-unused-default-fonts
Open

fix(shadcn): remove unused default Next.js fonts when init replaces them#11413
bunlongheng wants to merge 1 commit into
shadcn-ui:mainfrom
bunlongheng:fix/11124-remove-unused-default-fonts

Conversation

@bunlongheng

Copy link
Copy Markdown

Fixes #11124

Problem

When shadcn init applies a preset with a different font (e.g. Inter), the CLI rewrites the --font-sans theme mapping in globals.css but leaves the default create-next-app Geist import, declaration, and geistSans.variable className usage in layout.tsx. The unused font is still downloaded at runtime.

Fix

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 (--font-sans / --font-mono):

  • Removes the .variable usage from className (template literal, cn(), or bare expression)
  • Removes the variable declaration
  • Removes the named import from next/font/google if no longer used
  • Bails out safely if the font is referenced anywhere else (e.g. geistSans.className)
  • Geist_Mono is kept when only --font-sans is replaced, since --font-mono still maps to it

Testing

3 new tests covering:

  • The create-next-app repro from the issue (Geist replaced by Inter)
  • Sans + mono replacement (both Geist fonts removed)
  • Keep-if-referenced guard (geistSans.className preserved)

All 34 tests in update-fonts.test.ts pass; no existing test expectations changed.

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.
@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown
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.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Can you sign the commits please? See https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Init preset overwrites font mapping but leaves default GeistSans imported as dead weight

1 participant