Skip to content

Commit 03163d6

Browse files
committed
fix: #1444 async load google fonts
1 parent 6da3aab commit 03163d6

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

app/components/home.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
} from "react-router-dom";
2424
import { SideBar } from "./sidebar";
2525
import { useAppConfig } from "../store/config";
26-
import { useMaskStore } from "../store/mask";
2726

2827
export function Loading(props: { noLogo?: boolean }) {
2928
return (
@@ -91,12 +90,24 @@ const useHasHydrated = () => {
9190
return hasHydrated;
9291
};
9392

93+
const loadAsyncGoogleFont = () => {
94+
const linkEl = document.createElement("link");
95+
linkEl.rel = "stylesheet";
96+
linkEl.href =
97+
"/google-fonts/css2?family=Noto+Sans+SC:wght@300;400;700;900&display=swap";
98+
document.head.appendChild(linkEl);
99+
};
100+
94101
function Screen() {
95102
const config = useAppConfig();
96103
const location = useLocation();
97104
const isHome = location.pathname === Path.Home;
98105
const isMobileScreen = useMobileScreen();
99106

107+
useEffect(() => {
108+
loadAsyncGoogleFont();
109+
}, []);
110+
100111
return (
101112
<div
102113
className={

app/layout.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ export default function RootLayout({
3434
<head>
3535
<meta name="version" content={buildConfig.commitId} />
3636
<link rel="manifest" href="/site.webmanifest"></link>
37-
<link rel="preconnect" href="https://fonts.proxy.ustclug.org"></link>
38-
<link
39-
rel="stylesheet"
40-
href="https://fonts.proxy.ustclug.org/css2?family=Noto+Sans+SC:wght@300;400;700;900&display=swap"
41-
></link>
4237
<script src="/serviceWorkerRegister.js" defer></script>
4338
</head>
4439
<body>{children}</body>

next.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ const nextConfig = {
1010
source: "/api/proxy/:path*",
1111
destination: "https://api.openai.com/:path*",
1212
},
13+
{
14+
source: "/google-fonts/:path*",
15+
destination: "https://fonts.googleapis.com/:path*",
16+
},
1317
];
1418

1519
const apiUrl = process.env.API_URL;

0 commit comments

Comments
 (0)