refactor font preloading

This commit is contained in:
2022-07-18 17:27:49 -04:00
parent de604f2f04
commit a788f673e9
8 changed files with 59 additions and 87 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ const Menu = ({ ...rest }: MenuProps) => {
const isCurrent = item.href === `/${router.pathname.split("/")[1]}`;
return (
<Item key={index}>
<Item key={item.text || index}>
<MenuItem {...item} current={isCurrent} />
</Item>
);
+4 -4
View File
@@ -2,14 +2,14 @@ import { useMemo } from "react";
import { minify } from "uglify-js";
import { clientScript } from "./client";
export type ThemeScriptProps = {
export type ThemeScriptProps = JSX.IntrinsicElements["script"] & {
themeClassNames: {
[themeName: string]: string;
};
themeStorageKey: string;
};
const ThemeScript = ({ themeClassNames, themeStorageKey }: ThemeScriptProps) => {
const ThemeScript = ({ key, themeClassNames, themeStorageKey, ...rest }: ThemeScriptProps) => {
const minified = useMemo(() => {
// since the client function will end up being injected as a plain dumb string, we need to set dynamic values here:
const functionString = String(clientScript)
@@ -53,8 +53,8 @@ const ThemeScript = ({ themeClassNames, themeStorageKey }: ThemeScriptProps) =>
// TODO: using next/script *might* be possible after https://github.com/vercel/next.js/pull/36364 is merged.
return (
<script
key="restore-theme"
id="restore-theme"
key={key} // separate on purpose!
{...rest}
dangerouslySetInnerHTML={{
// make it an IIFE:
__html: `(function(){${minified}})()`,