Add fontsource and support override for registry:font install#9929
Add fontsource and support override for registry:font install#9929shadcn merged 19 commits intoshadcn-ui:mainfrom
Conversation
|
@kapishdima is attempting to deploy a commit to the shadcn-pro Team on Vercel. A member of the Team first needs to authorize it. |
|
@shadcn , I also have this issue in Fonttrio
I’m thinking - what if I make the installation use only fontsource (non-variable fonts)? That should be more stable Of course, I could add a check for whether the font exists in fontsource/variable, but it feels like that would increase the cognitive load in the code 🙃 |
|
Let me take a look. I'll come up with a solution. |
|
@shadcn just ping :DD |
| const fontName = fontSans.name.replace("font-", "") | ||
| const fontSourceDependency = `@fontsource-variable/${fontName}` | ||
| const fontSourceBase = `@fontsource/${fontName}` | ||
| const fontSourceVariable = `@fontsource-variable/${fontName}` |
There was a problem hiding this comment.
If a font does not have a variable variant, this will still fail right? eg. @fontsource-variable/lato will fail.
There was a problem hiding this comment.
Yes, I realized that after I created the PR, which is why I suggested installing only fontsource without variable. Alternatively, we could send a request and check whether the font exists in fontsource/variable
|
I'm checking if the following would be better: a {
"name": "font-inter",
"type": "registry:font",
"font": {
"family": "'Inter Variable', sans-serif",
"provider": "google",
"import": "Inter",
"variable": "--font-sans",
"dependency": "@fontsource-variable/inter" // ←
}
}{
"name": "font-lato",
"type": "registry:font",
"font": {
"family": "'Lato', sans-serif",
"provider": "google",
"import": "Lato",
"variable": "--font-sans",
"weight": ["400", "700"],
"dependency": "@fontsource/lato" // ←
}
} |
|
@shadcn Hmm, but what if the user has only My PR does a few things:
For example, |
|
@shadcn , I thought a lot about something like this. Then registry authors wouldn’t need to worry about whether a font is supported in fontsource: // ...
const response = await fetch(`https://registry.npmjs.org/@fontsource-variable/{fontName}`);
if(response.ok) {
tree.css[`@import "${fontSourceVariable}"`] = {}
}
// ... |
|
@shadcn , ping :D |
|
@shadcn, Do you have any solution? Or should I implement a check using a request? Because right now users cannot properly set the font in the TanStack Start application |
|
@kapishdima I wouldn't worry about fallback. Usage is at 97%. https://caniuse.com/variable-fonts |
…install, monorepo init" This reverts commit ad99fc9.
…ontrol. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
wdyt #10035? |
|
@shadcn , Let’s do it this way then, I’ll pass it on to Fonttrio from my side. Thanks! |
|
@kapishdima Ready to test with |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
@kapishdima ready when you are. |
|
I’ll go test it |
|
@shadcn , I tested installing a font that doesn’t exist in fontsource/variable - it works fine. There’s another thing though. I have a registry item like this {
"name": "fira-code",
"type": "registry:font",
"category": "Monospace",
"title": "Fira Code",
"description": "Fira Code — Monospace font.",
"font": {
"family": "Fira Code",
"provider": "google",
"import": "Fira_Code",
"variable": "--font-fira-code",
"weight": ["300", "400", "500", "600", "700"],
"subsets": [
"menu",
"cyrillic",
"cyrillic-ext",
"greek",
"greek-ext",
"latin",
"latin-ext",
"symbols2"
]
}
}
where --font-fira-code: Fira CodeBut the font-family in fontsource/variable is actually "Fira Code Variable". @font-face {
font-family: 'Fira Code Variable';
font-style: normal;
font-display: swap;
font-weight: 300 700;
src: url(./files/fira-code-cyrillic-ext-wght-normal.woff2) format('woff2-variations');
unicode-range: U+0460-052F,U+1C80-1C8A,U+20B4,U+2DE0-2DFF,U+A640-A69F,U+FE2E-FE2F;
}I can solve this at the registry-item level by simply setting What do you think? Is it better to let users specify the correct font-family themselves, or should this be handled in the CLI? |
|
Yes. That's right. The dependency field gives you explicit control here. Set family to match whatever package you're using:
It should be deterministic. The CLI shouldn't transform or guess font names. We leave that to the registry author. |
|
@shadcn Alright, everything works then. Thank you so much! |

When shadcn add installs a registry:font in a non-Next.js project (Vite, React Router, Astro, etc.), it always uses
@fontsource-variable/{fontName}This causes two problems:
fontsource/variable- it’s available infontsource@fontsource-variable/ packagesregister fonts with a "Variable" suffix (e.g., "Inter Variable" instead of "Inter"), which may not match what users expectGoal: Install both
@fontsource/{fontName}(base) and@fontsource-variable/{fontName}(variable), using CSS@supportsso that variable fonts are loaded only in clients that support them.