Next 15 app router ppr

From CraftOS-dev/craftbot-agent-bundles · View interactive version

Next 15 app router ppr is an AI agent skill from the GitHub repository CraftOS-dev/craftbot-agent-bundles. Source: https://nextjs.org/blog/next-15 · https://nextjs.org/docs

How to use this skill

Skill file

<!--

Source: https://nextjs.org/blog/next-15 · https://nextjs.org/docs

Authored: June 2026 for the frontend-engineer agent bundle.

-->

Next.js 15 — App Router, PPR, Turbopack

Next 15 (Oct 2024) made App Router the only first-class option, shipped

Partial Prerendering (PPR) stable in Nov 2024, made Turbopack the default

dev bundler (and stable for next build), and changed cookies() / headers()

/ params / searchParams to async.

When to use

"Turbopack", "Server Action", "middleware.ts", "Vercel deploy"

Setup

# New project — App Router + Tailwind + TypeScript
pnpm dlx create-next-app@latest my-app \
  --typescript --app --tailwind --turbopack --src-dir

cd my-app
pnpm dev      # uses Turbopack by default in Next 15

Upgrade an existing app:

pnpm add next@latest react@latest react-dom@latest
pnpm dlx @next/codemod@latest upgrade latest

Verify: pnpm next --version → 15.x.

No API keys required. For deploy: VERCEL_TOKEN (or use git integration).

Common recipes

Recipe 1 — Bootstrap `next.config.ts` with PPR

// next.config.ts (TypeScript config is supported in Next 15)
import type { NextConfig } from "next";

const config: NextConfig = {
  experimental: {
    ppr: "incremental", // opt-in per-route via `export const experimental_ppr = true`
    reactCompiler: true, // React 19 compiler — auto memoization
  },
  images: {
    formats: ["image/avif", "image/webp"],
    remotePatterns: [{ protocol: "https", hostname: "**.cdn.example.com" }],
  },
};

export default config;

Recipe 2 — File conventions cheat sheet

app/
  layout.tsx          # root layout (must define <html> + <body>)
  page.tsx            # /
  loading.tsx         # streaming Suspense fallback
  error.tsx           # error boundary (client component)
  not-found.tsx       # 404 UI
  global-error.tsx    # root-level fallback (replaces root layout on crash)
  template.tsx        # like layout but remounts on navigation
  middleware.ts       # edge runtime, runs before render
  app/blog/
    page.tsx          # /blog
    [slug]/
      page.tsx        # /blog/[slug]
      opengraph-image.tsx  # dynamic OG image
  app/api/webhook/
    route.ts          # Route Handler (POST/GET exports)

Recipe 3 — Async dynamic APIs (BREAKING CHANGE from Next 14)

// app/posts/[slug]/page.tsx
import { cookies, headers } from "next/headers";

export default async function Post({
  params,
  searchParams,
}: {
  params: Promise<{ slug: string }>;
  searchParams: Promise<{ ref?: string }>;
}) {
  const [{ slug }, { ref }, cookieStore, hdrs] = await Promise.all([
    params,
    searchParams,
    cookies(),
    headers(),
  ]);
  const theme = cookieStore.get("theme")?.value ?? "light";
  const ua = hdrs.get("user-agent");
  // ...
}

Codemod the migration: pnpm dlx @next/codemod@canary next-async-request-api ./app.

Recipe 4 — Partial Prerendering route

// app/dashboard/page.tsx
import { Suspense } from "react";

export const experimental_ppr = true; // opt this route in to PPR

export default function DashboardPage() {
  return (
    <>
      <StaticShell />                              {/* prerendered */}
      <Suspense fallback={<RecentSkeleton />}>
        <RecentActivity />                         {/* streamed at request */}
      </Suspense>
    </>
  );
}

async function RecentActivity() {
  const recent = await db.activity.findMany({ take: 10 });
  return <ul>{recent.map(a => <li key={a.id}>{a.label}</li>)}</ul>;
}

Build emits the static shell once; the Suspense boundary streams per request.

Recipe 5 — Route Handler (replaces `pages/api/*`)

// app/api/checkout/route.ts
import { NextResponse, type NextRequest } from "next/server";
import { z } from "zod";

export const runtime = "edge"; // or "nodejs" (default)
export const dynamic = "force-dynamic";

const Schema = z.object({ priceId: z.string().min(1) });

export async function POST(req: NextRequest) {
  const body = Schema.safeParse(await req.json());
  if (!body.success) return NextResponse.json({ error: body.error.flatten() }, { status: 400 });
  const session = await stripe.checkout.sessions.create({ /* ... */ });
  return NextResponse.json({ url: session.url }, { status: 200 });
}

Recipe 6 — Middleware with multi-tenant subdomain routing

// middleware.ts
import { NextResponse, type NextRequest } from "next/server";

export const config = { matcher: "/((?!api|_next|favicon.ico).*)" };

export function middleware(req: NextRequest) {
  const host = req.headers.get("host") ?? "";
  const subdomain = host.split(".")[0];
  if (subdomain && subdomain !== "www" && subdomain !== "app") {
    const url = req.nextUrl.clone();
    url.pathname = `/_tenants/${subdomain}${url.pathname}`;
    return NextResponse.rewrite(url);
  }
  return NextResponse.next();
}

Recipe 7 — `next/image` with priority on LCP

import Image from "next/image";

export function Hero() {
  return (
    <Image
      src="/hero.jpg"
      alt="Spring catalogue"
      width={1920}
      height={1080}
      priority           // preload, skip lazy-load
      sizes="100vw"
      className="h-auto w-full"
    />
  );
}

Only the single LCP image should have priority; everything else stays lazy.

Recipe 8 — `next/font` (self-host, zero CLS)

// app/layout.tsx
import { Inter } from "next/font/google";

const inter = Inter({ subsets: ["latin"], display: "swap" });

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en" className={inter.className}>
      <body>{children}</body>
    </html>
  );
}

Recipe 9 — `revalidatePath` and `revalidateTag`

"use server";
import { revalidatePath, revalidateTag } from "next/cache";

export async function publishPost(id: string) {
  await db.post.update({ where: { id }, data: { published: true } });
  revalidatePath("/blog");
  revalidatePath(`/blog/${id}`);
  revalidateTag("posts"); // invalidates anything fetched with { next: { tags: ["posts"] } }
}

Recipe 10 — `unstable_cache` for memoized data

import { unstable_cache } from "next/cache";

export const getTopPosts = unstable_cache(
  async (limit: number) => db.post.findMany({ orderBy: { views: "desc" }, take: limit }),
  ["top-posts"],
  { revalidate: 60, tags: ["posts"] },
);

Recipe 11 — Deploy

pnpm dlx vercel deploy --prod                            # Vercel (best DX)
pnpm dlx wrangler pages deploy ./out                     # Cloudflare Pages (run `next build && next export` first OR @cloudflare/next-on-pages)
pnpm dlx netlify deploy --prod                           # Netlify (use @netlify/plugin-nextjs)

Examples

Example 1: Migrate `pages/api/foo.ts` to `app/api/foo/route.ts`

Before (pages/api/users.ts):

export default function handler(req, res) {
  if (req.method !== "POST") return res.status(405).end();
  res.json({ ok: true });
}

After (app/api/users/route.ts):

import { NextResponse } from "next/server";
export async function POST() {
  return NextResponse.json({ ok: true });
}

Example 2: Migrate `getServerSideProps` to async Server Component

Before:

export async function getServerSideProps({ params }) {
  const post = await db.post.findUnique({ where: { id: params.id } });
  return { props: { post } };
}
export default function Page({ post }) { return <article>{post.body}</article>; }

After:

export default async function Page({ params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  const post = await db.post.findUnique({ where: { id } });
  return <article>{post.body}</article>;
}

Edge cases / gotchas

14 sync calls throw at runtime in 15. Run the codemod.

Wrap in Suspense and let loading.tsx show a fallback.

formData). Bind extra args with .bind(null, extra)` or hidden form fields.

exporting experimental_ppr = true from the route. Setting it to true

globally is allowed but uncommon.

https://nextjs.org/docs/app/api-reference/turbopack for parity. If a plugin

isn't supported, fall back to webpack (pnpm next dev without --turbo).

{ ssr: false })` skips SSR rendering. Useful for components that touch

window.

{ bodySizeLimit: "2mb" } in next.config.ts`.

Sources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.