Best way to include fonts?
I am importing
on
__root but this leads to the font not being available in stack. What is the recommended way to use fonts?
thanks!19 Replies
rising-crimsonOP•6mo ago
There is this guide, but moving the import to the css does not fix the issue:
https://tanstack.com/start/latest/docs/framework/react/migrate-from-next-js#fonts
Migrate from Next.js | TanStack Start React Docs
[!IMPORTANT] This guide is based on the upcoming work in the alpha branch of TanStack Start. We are actively working on exciting new features, and this guide will be updated soon. This guide provides...
rising-crimsonOP•6mo ago
For now Im fixing it like this:
but this feels very brittle, and annoying to mantain, since it will break with every release of the font
eastern-cyan•6mo ago
why you dont use tailwindcss and css ?
rising-crimsonOP•6mo ago
Loading the fonts from google is somewhat sketchy since it gives google information I'd prefer not to give if I can avoid. IE, I prefer to self host my fonts
Using the self hosted fonts in CSS / tailwind, leads to the same error.
eastern-cyan•6mo ago
btw there is also: https://github.com/unjs/fontaine
What happens if you place the fonts in "public/fonts" for example? It should correctly resolve i think
rising-crimsonOP•6mo ago
yes, but i would have to download them, and not rely on npm. I'm happy to leave someone that responsability 😅
eastern-cyan•6mo ago
I mean, fonts dont really change that often for that effort tbh :p
other-emerald•6mo ago
I'm importing the font from fontsource in the
__root.tsx file and its working. I tried also with tailwind, no issuerising-crimsonOP•6mo ago
are you already devinxed?
other-emerald•6mo ago
yes I tried on a fresh install
rising-crimsonOP•6mo ago
I see, wonder what im doing wrong
or missing
other-emerald•6mo ago
This is all I'm doing to make it work:
foreign-sapphire•2w ago
anyone got a success with setting up custom font?
unwilling-turquoise•2w ago
@marko can you share a project that shows what you tried so far so we can help debug this?
foreign-sapphire•2w ago
ah sorry for the noise, works perfect, note to myself I shouldn't code more then 10 hours per day 😄
unwilling-turquoise•2w ago
want to create an example for the router/start repo?
foreign-sapphire•2w ago
would love to, as soon as I acquire some free time 🤞
It basically works as written here https://tanstack.com/start/latest/docs/framework/react/migrate-from-next-js#fonts but I guess it would be a bit better if this topic/chapter was also mentioned somewhere else in the docs, since it doesn't apply to nextjs migration only.
in my case whole tanstack project it's setup in docker, and I forgot to rebuild container when I added font as npm package
foreign-sapphire•2w ago
it works great btw, most of the pages are scored 100 🥳

unwilling-turquoise•2w ago
very nice