### Installation Source: https://github.com/vercel-labs/next-skills/blob/main/README.md Install essential Next.js best practices skills or all skills. ```bash # Install essentials (recommended) npx skills add vercel-labs/next-skills --skill next-best-practices # Or install everything npx skills add vercel-labs/next-skills ``` -------------------------------- ### Example: Get Errors via MCP Source: https://github.com/vercel-labs/next-skills/blob/main/skills/next-best-practices/debug-tricks.md Example curl command to fetch errors using the MCP endpoint. ```bash curl -X POST http://localhost:/_next/mcp \ -H "Content-Type: application/json" \ -H "Accept: application/json, text/event-stream" \ -d '{"jsonrpc":"2.0","id":"1","method":"tools/call","params":{"name":"get_errors","arguments":{}}}' ``` -------------------------------- ### Code Examples Source: https://github.com/vercel-labs/next-skills/blob/main/AGENTS.md Examples showing bad vs good patterns. ```tsx // Bad: description of the problem // Good: description of the solution ``` -------------------------------- ### Static Content Example Source: https://github.com/vercel-labs/next-skills/blob/main/skills/next-cache-components/SKILL.md Example of static content that is auto-prerendered at build time. ```tsx export default function Page() { return (

Our Blog

{/* Static - instant */}
) } ``` -------------------------------- ### OpenNext CLI Commands Source: https://github.com/vercel-labs/next-skills/blob/main/skills/next-best-practices/self-hosting.md Example commands for setting up a project with OpenNext for serverless deployment. ```bash npx create-sst@latest # or npx @opennextjs/aws build ``` -------------------------------- ### Dynamic Content Example (Suspense) Source: https://github.com/vercel-labs/next-skills/blob/main/skills/next-cache-components/SKILL.md Example of runtime data that must be fresh, wrapped in Suspense. ```tsx import { Suspense } from 'react' export default function Page() { return ( <> {/* Cached */} Loading...

}> {/* Dynamic - streams in */}
) } async function UserPreferences() { const theme = (await cookies()).get('theme')?.value return

Theme: {theme}

} ``` -------------------------------- ### Docker Compose Configuration Source: https://github.com/vercel-labs/next-skills/blob/main/skills/next-best-practices/self-hosting.md Example `docker-compose.yml` for deploying a Next.js application. ```yaml version: '3.8' services: web: build: . ports: - "3000:3000" environment: - NODE_ENV=production restart: unless-stopped healthcheck: test: ["CMD", "wget", "-q", "--spider", "http://localhost:3000/api/health"] interval: 30s timeout: 10s retries: 3 ``` -------------------------------- ### Skill Contribution Structure Source: https://github.com/vercel-labs/next-skills/blob/main/README.md Example YAML frontmatter for a new skill. ```yaml --- name: next-skill-name description: Brief description user-invocable: false # for background skills --- ``` -------------------------------- ### Migrating from Webpack to Turbopack Source: https://github.com/vercel-labs/next-skills/blob/main/skills/next-best-practices/bundling.md Example of `next.config.js` showing configurations compatible with Turbopack versus those that are Webpack-only. ```js // next.config.js module.exports = { // Good: Works with Turbopack serverExternalPackages: ['package'], transpilePackages: ['package'], // Bad: Webpack-only - migrate away from this webpack: (config) => { // custom webpack config }, } ``` -------------------------------- ### Runtime Configuration Fetching Source: https://github.com/vercel-labs/next-skills/blob/main/skills/next-best-practices/self-hosting.md Example of fetching runtime configuration from an API endpoint in a Next.js application. ```typescript // app/api/config/route.ts export async function GET() { return Response.json({ apiUrl: process.env.API_URL, features: process.env.FEATURES?.split(','), }); } ``` -------------------------------- ### Complete Cache Components Example Source: https://github.com/vercel-labs/next-skills/blob/main/skills/next-cache-components/SKILL.md A full example demonstrating the usage of `use cache`, `cacheLife`, and `cacheTag` within a Next.js dashboard page. ```tsx import { Suspense } from 'react' import { cookies } from 'next/headers' import { cacheLife, cacheTag } from 'next/cache' export default function DashboardPage() { return ( <> {/* Static shell - instant from CDN */}

Dashboard

{/* Cached - fast, revalidates hourly */} {/* Dynamic - streams in with fresh data */} }> ) } async function Stats() { 'use cache' cacheLife('hours') cacheTag('dashboard-stats') const stats = await db.stats.aggregate() return } async function Notifications() { const userId = (await cookies()).get('userId')?.value const notifications = await db.notifications.findMany({ where: { userId, read: false } }) return } ``` -------------------------------- ### Route Handlers Environment Behavior Example Source: https://github.com/vercel-labs/next-skills/blob/main/skills/next-best-practices/route-handlers.md Shows an example of code that will not work in route handlers due to the lack of React DOM APIs, highlighting the server-like environment. ```typescript // Bad: This won't work - no React DOM in route handlers import { renderToString } from 'react-dom/server' export async function GET() { const html = renderToString() // Error! return new Response(html) } ``` -------------------------------- ### Cached Content Example (`use cache`) Source: https://github.com/vercel-labs/next-skills/blob/main/skills/next-cache-components/SKILL.md Example of async data that doesn't need fresh fetches every request, using the 'use cache' directive. ```typescript async function BlogPosts() { 'use cache' cacheLife('hours') const posts = await db.posts.findMany() return } ``` -------------------------------- ### Dockerfile for Standalone Output Source: https://github.com/vercel-labs/next-skills/blob/main/skills/next-best-practices/self-hosting.md A Dockerfile example for building a production-ready Next.js application using standalone output. ```dockerfile FROM node:20-alpine AS base # Install dependencies FROM base AS deps WORKDIR /app COPY package.json package-lock.json* ./ RUN npm ci # Build FROM base AS builder WORKDIR /app COPY --from=deps /app/node_modules ./ COPY . . RUN npm run build # Production FROM base AS runner WORKDIR /app ENV NODE_ENV=production # Create non-root user RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs # Copy standalone output COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/.next/static ./.next/static COPY --from=builder /app/public ./public USER nextjs EXPOSE 3000 ENV PORT=3000 ENV HOSTNAME="0.0.0.0" CMD ["node", "server.js"] ``` -------------------------------- ### Related Skills Source: https://github.com/vercel-labs/next-skills/blob/main/README.md Install agent skills for React-specific patterns. ```bash npx skills add vercel-labs/agent-skills --skill vercel-react-best-practices ``` -------------------------------- ### Next.js Upgrade Skill Source: https://github.com/vercel-labs/next-skills/blob/main/README.md Install the skill for upgrading between Next.js versions. ```bash npx skills add vercel-labs/next-skills --skill next-upgrade ``` -------------------------------- ### Loading Strategies for next/script Source: https://github.com/vercel-labs/next-skills/blob/main/skills/next-best-practices/scripts.md Provides examples of different loading strategies available for `next/script`. ```tsx // afterInteractive (default) - Load after page is interactive // Good: Next.js Script component import Script from 'next/script'