From b29bdb4e05d248f17c22e7935cd3a65d7b376264 Mon Sep 17 00:00:00 2001 From: James Calcaben Date: Sat, 22 Apr 2023 03:05:25 -0500 Subject: [PATCH 1/4] Fix font flashing bug by pre-loading font --- next.config.js | 15 +++++++++++- package.json | 7 +++--- pages/_app.tsx | 29 ++++++++++++++-------- yarn.lock | 66 +++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 102 insertions(+), 15 deletions(-) diff --git a/next.config.js b/next.config.js index 28b694f..d11822d 100644 --- a/next.config.js +++ b/next.config.js @@ -3,4 +3,17 @@ module.exports = { reactStrictMode: true, // exportPathMap: () => {} swcMinify: true, -} + webpack: (config) => { + config.module = { + ...config.module, + rules: [ + ...config.module.rules, + { + test: /\.(woff|woff2)$/, + type: 'asset/resource' + }, + ], + }; + return config; + }, +}; diff --git a/package.json b/package.json index e934804..74ed6c9 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,9 @@ "@vercel/analytics": "^0.1.6", "framer-motion": "^6", "next": "12.3.1", + "react": "18.2.0", "react-dom": "18.2.0", - "react-icons": "4.7.1", - "react": "18.2.0" + "react-icons": "4.7.1" }, "devDependencies": { "@types/node": "18.7.2", @@ -28,6 +28,7 @@ "@types/react-dom": "18.0.6", "eslint": "8.24.0", "eslint-config-next": "12.3.1", - "typescript": "4.9.4" + "typescript": "4.9.4", + "url-loader": "^4.1.1" } } diff --git a/pages/_app.tsx b/pages/_app.tsx index c1a2d70..b6cd554 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -1,16 +1,18 @@ // Importing fonts (there's probably a better way to do this...) -import '@fontsource/crimson-text' + +import "@fontsource/crimson-text"; +import crimsonTextLatin from "@fontsource/crimson-text/files/crimson-text-latin-400-normal.woff2"; // Setup for Chakra and Next environments -import { ChakraProvider } from '@chakra-ui/react' -import { Analytics } from '@vercel/analytics/react' +import { ChakraProvider } from "@chakra-ui/react"; +import { Analytics } from "@vercel/analytics/react"; -import { type AppProps } from 'next/app' -import Head from 'next/head' +import { type AppProps } from "next/app"; +import Head from "next/head"; -import { theme } from '../lib/theme' -import { Header } from '../components/header' -import { Footer } from '../components/footer' +import { theme } from "../lib/theme"; +import { Header } from "../components/header"; +import { Footer } from "../components/footer"; function MyApp({ Component, pageProps }: AppProps) { return ( @@ -22,13 +24,20 @@ function MyApp({ Component, pageProps }: AppProps) { content="Open Austin is a volunteer citizen brigade advocating for open government, open data, and civic application development since 2009." /> +