From fffc91a26d069ba26f344a689ad02c24068155ca Mon Sep 17 00:00:00 2001 From: Gabe Mendoza Date: Tue, 10 Dec 2024 21:21:14 -0600 Subject: [PATCH] Optimize package imports and add error pages (#103) * control * treeshaking * optimize packages * treeshaking * Update apps/nextjs/src/app/forbidden.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Gabe Mendoza * unauth page * lint --------- Signed-off-by: Gabe Mendoza Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- apps/nextjs/next.config.ts | 43 ++++++++++++++++++++++-- apps/nextjs/src/app/forbidden.tsx | 19 +++++++++++ apps/nextjs/src/app/unauthorized.tsx | 49 ++++++++++++++++++++++++++++ cspell.config.yaml | 1 + 4 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 apps/nextjs/src/app/forbidden.tsx create mode 100644 apps/nextjs/src/app/unauthorized.tsx diff --git a/apps/nextjs/next.config.ts b/apps/nextjs/next.config.ts index be642d88..4e6a693c 100644 --- a/apps/nextjs/next.config.ts +++ b/apps/nextjs/next.config.ts @@ -11,7 +11,7 @@ const withBundleAnalyzer = require("@next/bundle-analyzer")({ enabled: process.env.ANALYZE === "true", }); -export default withBundleAnalyzer({ +const nextConfig: NextConfig = { reactStrictMode: true, experimental: { reactCompiler: true, @@ -26,6 +26,43 @@ export default withBundleAnalyzer({ staticGenerationRetryCount: 2, staticGenerationMaxConcurrency: 8, staticGenerationMinPagesPerWorker: 25, + turbo: { + treeShaking: true, + }, + webpackMemoryOptimizations: true, + optimizePackageImports: [ + "@battle-stadium/api", + "@battle-stadium/auth", + "@battle-stadium/db", + "@battle-stadium/ui", + "@battle-stadium/validators", + "@clerk/backend", + "@clerk/clerk-react", + "@clerk/nextjs", + "@trpc/client", + "@trpc/react-query", + "@trpc/server", + "@uploadthing/react", + "react-hook-form", + "discord-api-types", + "discord-interactions", + "discord.js", + "openapi-fetch", + "openapi-typescript-helpers", + "pokedex-promise-v2", + "@pkmn/sets", + "@pkmn/types", + "@rails/actioncable", + "@vercel/analytics", + "@vercel/flags", + "@vercel/functions", + "@vercel/kv", + "@vercel/speed-insights", + "@aws-sdk/credential-provider-web-identity", + "cookie", + "tweetnacl", + "zod", + ], }, expireTime: 3600, @@ -66,4 +103,6 @@ export default withBundleAnalyzer({ /** We already do linting and typechecking as separate tasks in CI */ eslint: { ignoreDuringBuilds: false }, typescript: { ignoreBuildErrors: false }, -} satisfies NextConfig); +}; + +export default withBundleAnalyzer(nextConfig); diff --git a/apps/nextjs/src/app/forbidden.tsx b/apps/nextjs/src/app/forbidden.tsx new file mode 100644 index 00000000..67162bd2 --- /dev/null +++ b/apps/nextjs/src/app/forbidden.tsx @@ -0,0 +1,19 @@ +import Link from "next/link"; + +export default function Forbidden() { + return ( +
+
+

Forbidden

+

You are not authorized to access this resource.

+

+ If you believe this is an error, please contact support. +

+ Return Home +
+
+ ); +} diff --git a/apps/nextjs/src/app/unauthorized.tsx b/apps/nextjs/src/app/unauthorized.tsx new file mode 100644 index 00000000..15623da0 --- /dev/null +++ b/apps/nextjs/src/app/unauthorized.tsx @@ -0,0 +1,49 @@ +import Link from "next/link"; + +export default function Unauthorized() { + const returnUrl = + typeof window !== "undefined" ? window.location.pathname : ""; + const signInUrl = `/sign-in${returnUrl ? `?returnUrl=${encodeURIComponent(returnUrl)}` : ""}`; + + return ( + + ); +} + +interface ErrorPageLayoutProps { + title: string; + message: string; + actionLink: { + href: string; + text: string; + }; + children?: React.ReactNode; +} + +function ErrorPageLayout({ + title, + message, + actionLink, + children, +}: ErrorPageLayoutProps) { + return ( +
+
+

{title}

+

{message}

+ {children} + {actionLink.text} +
+
+ ); +} diff --git a/cspell.config.yaml b/cspell.config.yaml index a23e5436..cc9051cc 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -36,6 +36,7 @@ dictionaries: - markdown - lorem-ipsum words: + - actioncable - adbanner - adsbygoogle - adsense