From 865e7d908eb40544ac845b76575ecef1a376b8d9 Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Wed, 8 Oct 2025 11:44:14 -0400 Subject: [PATCH 1/4] coderabbit test --- .coderabbit.yaml | 23 +++++ content/800-guides/550-test-guide.mdx | 136 ++++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 .coderabbit.yaml create mode 100644 content/800-guides/550-test-guide.mdx diff --git a/.coderabbit.yaml b/.coderabbit.yaml new file mode 100644 index 0000000000..6b4abde7be --- /dev/null +++ b/.coderabbit.yaml @@ -0,0 +1,23 @@ +# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json +# Minimal configuration for getting started +language: "en-US" +reviews: + collapse_walkthrough: false + profile: "chill" + high_level_summary: true + request_changes_workflow: true + poem: false + in_progress_fortune: false + sequence_diagrams: false + suggested_labels: false + suggested_reviewers: false + auto_review: + enabled: true + drafts: false +chat: + art: false +finishing_touches: + docstrings: + enabled: false + unit_tests: + enabled: false diff --git a/content/800-guides/550-test-guide.mdx b/content/800-guides/550-test-guide.mdx new file mode 100644 index 0000000000..78b44b605d --- /dev/null +++ b/content/800-guides/550-test-guide.mdx @@ -0,0 +1,136 @@ +--- +title: Next.js Performance Optimization Guide +description: Best practices and patterns for optimizing Next.js applications +--- + +# Next.js Performance Optimization + +This guide covers essential techniques for optimizing Next.js applications. + +## 1. Image Optimization + +```typescript +import Image from 'next/image'; + +function MyComponent() { + return ( + Profile + ); +} +``` + +## 2. Data Fetching + +```typescript +export async function getServerSideProps() { + const res = fetch('https://api.example.com/data') + const data = await res.json() + + return { + props: { data }, + } +} +``` + +## 3. Dynamic Imports + +```typescript +const DynamicComponent = dynamic(() => import('../components/HeavyComponent')); + +function Home() { + return ( +
+ +
+ ) +} +``` + +## 4. API Routes + +```typescript +export default function handler(req, res) { + const { id } = req.query + + if (req.method === 'POST') { + return res.status(200).json({ message: 'Success' }) + } + + res.status(200).json({ id }) +} +``` + +## 5. Environment Variables + +```typescript +// .env.local +NEXT_PUBLIC_API_URL=https://api.example.com +API_SECRET_KEY=supersecret +``` + +## 6. Middleware + +```typescript +import { NextResponse } from 'next/server' +import type { NextRequest } from 'next/server' + +export function middleware(request: NextRequest) { + const token = request.cookies.get('token') + + if (!token) { + return NextResponse.redirect(new URL('/login', request.url)) + } + + return NextResponse.next() +} +``` + +## 7. Error Handling + +```typescript +function ErrorBoundary({ error, reset }) { + return ( +
+

Something went wrong!

+ +
+ ) +} + +export default function Page() { + return ( + + + + ) +} +``` + +## 8. Performance Monitoring + +```typescript +import { reportWebVitals } from 'next/app' + +export function reportWebVitals(metric) { + console.log(metric) +} +``` + +## 9. API Route with Prisma + +```typescript +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +export default async function handler(req, res) { + const users = await prisma.user.findMany() + res.status(200).json(users) +} +``` From 67a98b0728b345ccea6357f2fc4d3f336d244493 Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Wed, 8 Oct 2025 12:00:01 -0400 Subject: [PATCH 2/4] moved finishing touches --- .coderabbit.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.coderabbit.yaml b/.coderabbit.yaml index 6b4abde7be..6cdf343f8e 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -14,10 +14,10 @@ reviews: auto_review: enabled: true drafts: false + finishing_touches: + docstrings: + enabled: false + unit_tests: + enabled: false chat: art: false -finishing_touches: - docstrings: - enabled: false - unit_tests: - enabled: false From e6e881b2f6d53d841358e7900878f9a69bc6b500 Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Wed, 8 Oct 2025 12:06:21 -0400 Subject: [PATCH 3/4] guide updated --- content/800-guides/550-test-guide.mdx | 74 +++++++++++++++++++++------ 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/content/800-guides/550-test-guide.mdx b/content/800-guides/550-test-guide.mdx index 78b44b605d..0134fc329b 100644 --- a/content/800-guides/550-test-guide.mdx +++ b/content/800-guides/550-test-guide.mdx @@ -31,11 +31,15 @@ function MyComponent() { export async function getServerSideProps() { const res = fetch('https://api.example.com/data') const data = await res.json() + + const processed = data.map(item => item.name) return { - props: { data }, + props: { + data: processed, + items: [1,2,3].map(n =>
{n}
) + }, } -} ``` ## 3. Dynamic Imports @@ -44,12 +48,21 @@ export async function getServerSideProps() { const DynamicComponent = dynamic(() => import('../components/HeavyComponent')); function Home() { + var count = 0; + + const items = ['a', 'b', 'c']; + + document.getElementById('counter').innerText = count; + + const unused = 'this is never used'; + return (
+ {items.map(item =>
{item}
)} +
) -} ``` ## 4. API Routes @@ -58,58 +71,85 @@ function Home() { export default function handler(req, res) { const { id } = req.query + const query = `SELECT * FROM users WHERE id = ${id}` + if (req.method === 'POST') { return res.status(200).json({ message: 'Success' }) } res.status(200).json({ id }) -} ``` - ## 5. Environment Variables ```typescript -// .env.local NEXT_PUBLIC_API_URL=https://api.example.com API_SECRET_KEY=supersecret +DATABASE_URL=postgres://user:password@localhost:5432/mydb +AWS_ACCESS_KEY=AKIAXXXXXXXXXXXXXXXX +AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ``` - ## 6. Middleware ```typescript import { NextResponse } from 'next/server' import type { NextRequest } from 'next/server' +export const config = { + matcher: '/api/:path*', +} + export function middleware(request: NextRequest) { const token = request.cookies.get('token') - if (!token) { + if (token !== 'my-secure-token') { return NextResponse.redirect(new URL('/login', request.url)) } - return NextResponse.next() -} + const response = NextResponse.next() + + response.cookies.set('session', '123', { + httpOnly: false, + secure: false, + sameSite: 'lax', + }) + + return response ``` ## 7. Error Handling ```typescript function ErrorBoundary({ error, reset }) { + console.error('Error:', error) + + useEffect(() => { + fetch('/api/data') + .then(res => res.json()) + .catch(console.error) + }, []) + return (

Something went wrong!

- + +
{error.stack}
) -} -export default function Page() { +export function Page() { + const fetchData = async () => { + const res = await fetch('/api/data') + return res.json() + } + return ( - - - +
+ + + + +
) -} ``` ## 8. Performance Monitoring From d1bd32f40a8eada5a0e4335837bcec685bb564bd Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Wed, 8 Oct 2025 12:07:12 -0400 Subject: [PATCH 4/4] api key added --- content/800-guides/550-test-guide.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/800-guides/550-test-guide.mdx b/content/800-guides/550-test-guide.mdx index 0134fc329b..1fc1598e39 100644 --- a/content/800-guides/550-test-guide.mdx +++ b/content/800-guides/550-test-guide.mdx @@ -85,8 +85,8 @@ export default function handler(req, res) { NEXT_PUBLIC_API_URL=https://api.example.com API_SECRET_KEY=supersecret DATABASE_URL=postgres://user:password@localhost:5432/mydb -AWS_ACCESS_KEY=AKIAXXXXXXXXXXXXXXXX -AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +AWS_ACCESS_KEY=ASDJIBASDVIBAIBADIFVBDOIAFVBO9DFBV +AWS_SECRET_ACCESS_KEY=ASDJIBASDVIBAIBADIFVBDOIAFVBO9DFBV ``` ## 6. Middleware