Skip to content
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

♻️ Inter Font - Added preload to avoid FOUT issues #700

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gatsby-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import AppProvider from 'store/provider';
// import axios from 'axios';
import { ApplicationInsights } from '@microsoft/applicationinsights-web';
import { SeverityLevel } from '@microsoft/applicationinsights-web';
import '@fontsource/inter';
import '@fontsource-variable/inter';
// import { siteUrlCn } from './site-config.js';

const environment = process.env.NODE_ENV;
Expand Down
15 changes: 15 additions & 0 deletions gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { renderToString } from 'react-dom/server';
import { ServerStyleSheet } from 'styled-components';
import AppProvider from 'store/provider';
import wrapPageElementWithTransition from 'helpers/wrapPageElement';
import '@fontsource-variable/inter';
import interWoff2 from '@fontsource-variable/inter/files/inter-latin-wght-normal.woff2?url';

export const replaceRenderer = ({
bodyComponent,
Expand All @@ -20,5 +22,18 @@ export const replaceRenderer = ({
setHeadComponents(styleElement);
};

export const onRenderBody = ({ setHeadComponents }) => {
setHeadComponents([
<link
rel="preload"
as="font"
type="font/woff2"
href={interWoff2}
crossOrigin="anonymous"
key="interPreload"
/>,
]);
};

// Page Transitions
export const wrapPageElement = wrapPageElementWithTransition;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"@babel/core": "^7.25.2",
"@brainhubeu/react-carousel": "^2.0.4",
"@fontsource/inter": "^5.1.0",
"@fontsource-variable/inter": "^5.1.0",
"@fortawesome/free-brands-svg-icons": "^6.6.0",
"@fortawesome/free-regular-svg-icons": "^6.6.0",
"@microsoft/applicationinsights-web": "^3.3.3",
Expand Down
2 changes: 1 addition & 1 deletion src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}

html {
font-family: "Inter",Helvetica Neue,Helvetica,Arial,sans-serif;
font-family: "Inter Variable", sans-serif;
color:#333;
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2023,10 +2023,10 @@ __metadata:
languageName: node
linkType: hard

"@fontsource/inter@npm:^5.1.0":
"@fontsource-variable/inter@npm:^5.1.0":
version: 5.1.0
resolution: "@fontsource/inter@npm:5.1.0"
checksum: 10c0/48c740b8a311908ca9527bf598e759bdfad6429f730450cc4904877915537e857a322db3ff7ade0bf731a3853ab34e611638d560529774a7e94ca2237735c86b
resolution: "@fontsource-variable/inter@npm:5.1.0"
checksum: 10c0/6b46019c71380f6e18427b4b19468a9a656609fcf613b8472f7b928ec1bc6f13b03d1dd0bb9536cd168a53e58c009465e2245cd87ef57f9925a07d2306bd8f58
languageName: node
linkType: hard

Expand Down Expand Up @@ -21397,7 +21397,7 @@ __metadata:
"@babel/eslint-parser": "npm:^7.25.1"
"@babel/preset-react": "npm:^7.24.7"
"@brainhubeu/react-carousel": "npm:^2.0.4"
"@fontsource/inter": "npm:^5.1.0"
"@fontsource-variable/inter": "npm:^5.1.0"
"@fortawesome/fontawesome-svg-core": "npm:^6.6.0"
"@fortawesome/free-brands-svg-icons": "npm:^6.6.0"
"@fortawesome/free-regular-svg-icons": "npm:^6.6.0"
Expand Down