-
Notifications
You must be signed in to change notification settings - Fork 1k
chore: preload inter font #19455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: preload inter font #19455
Conversation
High-level: Preloading Inter via a bundler URL + Helmet looks good for the main app, and the ambient module declaration for Main gap: Storybook doesn’t render Suggested fix (uses existing HelmetProvider in preview): // site/.storybook/preview.tsx
import { Helmet } from "react-helmet-async";
import interWoff2 from "@fontsource-variable/inter/files/inter-latin-wght-normal.woff2?url";
const withHelmet: Decorator = (Story) => {
return (
<HelmetProvider>
<Helmet>
<link
rel="preload"
as="font"
type="font/woff2"
href={interWoff2}
crossOrigin="anonymous"
/>
</Helmet>
<Story />
</HelmetProvider>
);
}; Alternatively, add a Nice-to-have:
If you add the Storybook preload, I’m confident this will address the snapshot variability. Happy to re-review after that change. |
@BrunoQuaresma Should the link tag be added to .storybook/preview.tsx instead of App.tsx? |
I think it would be useful to preload the Inter font in the app too. Wdyt? |
or actually, maybe have both preloads in App and preview.tsx |
Good catch! I we don't use the App in Storybook 🤦 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced this actually does anything. for react-helmet to add this <link>
to the head...
- all of the javascript needs to be loaded
- javascript needs to be parsed and executed
- the virtual dom needs to be constructed
- the reconciler needs to apply that virtual dom to the document
- by this point I think the browser has probably already started loading the styles, because other elements have been applied into the dom which require its presence.
these storybook docs seem more promising to me: https://storybook.js.org/docs/configure/integration/images-and-assets#referencing-fonts-in-stories
also, about the import types: vite provides those types, we just haven't ever enabled them for some reason. 🙃 pr to fix: #19477 |
@aslilac that makes sense. About the docs you mentioned, I don't see a clear way to make |
Thinking more about that, I don't think it would work since the file location would be in different places. |
ee682c8
to
237aeac
Compare
I think I got it working. I didn't know vite was smart enough to figure out how to bundle static assets from node_modules :) |
I think you can even leave off the vite is pretty clever 😄 |
@aslilac I tried, but it does not 😞 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks bruno!
one last thought before you merge this tho, would it be worth adding a preload for the monospace font we use in the terminal stories? I think flickering has been a big problem there in the past. but in terms of inter specifically, this looks good.
This aims to solve font rendering issues in Storybook like the inconsistent snapshot below.
Inconsistent snapshot:

References: