From 954d454fe11787e8d1a318ef31fdb54a047bf165 Mon Sep 17 00:00:00 2001 From: awtkns Date: Tue, 25 Apr 2023 23:03:37 +0100 Subject: [PATCH] :bug: Improve rate limiting for local dev --- src/components/pdf/MyDocument.tsx | 9 ++++----- src/components/pdf/PDFButton.tsx | 11 +++++++---- tsconfig.json | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/components/pdf/MyDocument.tsx b/src/components/pdf/MyDocument.tsx index bc5b7ab48b..e552896a58 100644 --- a/src/components/pdf/MyDocument.tsx +++ b/src/components/pdf/MyDocument.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { Document, Page, Text, StyleSheet, Font } from "@react-pdf/renderer"; +import { Document, Font, Page, StyleSheet, Text } from "@react-pdf/renderer"; Font.register({ family: "Roboto,SourceHanSansCN", @@ -27,11 +27,10 @@ const styles = StyleSheet.create({ }, }); -interface MyDocumentProps { +// NOTE: This should only ever be imported dynamically to reduce load times +const MyDocument: React.FC<{ content: string; -} - -const MyDocument: React.FC = ({ content }) => ( +}> = ({ content }) => ( {content} diff --git a/src/components/pdf/PDFButton.tsx b/src/components/pdf/PDFButton.tsx index f70c36b6b7..aca041dd16 100644 --- a/src/components/pdf/PDFButton.tsx +++ b/src/components/pdf/PDFButton.tsx @@ -2,7 +2,6 @@ import WindowButton from "../WindowButton"; import { FaFilePdf } from "react-icons/fa"; import { pdf } from "@react-pdf/renderer"; import React, { memo } from "react"; -import MyDocument from "./MyDocument"; import type { Message } from "../../types/agentTypes"; import { useTranslation } from "react-i18next"; @@ -17,6 +16,10 @@ const PDFButton = ({ const content = getContent(messages); const downloadPDF = async () => { + const MyDocument = (await import("./MyDocument")).default as React.FC<{ + content: string; + }>; + const blob = await pdf().toBlob(); const url = URL.createObjectURL(blob); const link = document.createElement("a"); @@ -41,15 +44,15 @@ const PDFButton = ({ }; const getContent = (messages: Message[]): string => { - const [ t ] = useTranslation(); + const [t] = useTranslation(); // Note "Thinking" messages have no `value` so they show up as new lines return messages .map((message) => { if (message.type == "goal") { - return `${t('Goal: ')}${message.value}`; + return `${t("Goal: ")}${message.value}`; } if (message.type == "task") { - return `${t('Adding Task: ')}${message.value}`; + return `${t("Adding Task: ")}${message.value}`; } return message.value; }) diff --git a/tsconfig.json b/tsconfig.json index 15466e927f..4575b2a968 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,5 +17,5 @@ "noUncheckedIndexedAccess": true }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.cjs", "**/*.mjs", "**/*.js"], - "exclude": ["node_modules"] + "exclude": ["node_modules", "venv"] }