Generate Next.js App Router pages and route handlers: async params, metadata exports, loading and error files, typed route handlers, explicit caching and sitemap/robots files.
.devin/rules/windsurf-next-js-page-generation.md. Downloaded files need to be placed in that repository path.---
trigger: glob
globs: "**/*"
---
When generating Next.js App Router code (Next.js 15/16):
## Conventions
- Use the `app/` directory: `page.tsx`, `layout.tsx`, `loading.tsx`, `error.tsx`, `not-found.tsx`, and `route.ts` for API endpoints. Pages and layouts are Server Components by default.
- `params` and `searchParams` are Promises in pages, layouts, metadata functions and route handlers; await them.
## Metadata
```tsx
// app/blog/[slug]/page.tsx
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { getPost } from '@/lib/posts';
type Props = { params: Promise<{ slug: string }> };
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { slug } = await params;
const post = await getPost(slug);
if (!post) return {};
return {
title: post.title,
description: post.excerpt,
alternates: { canonical: `/blog/${slug}` },
openGraph: { title: post.title, description: post.excerpt, type: 'article' },
};
}
export default async function BlogPostPage({ params }: Props) {
const { slug } = await params;
const post = await getPost(slug);
if (!post) notFound();
return (
<article>
<h1>{post.title}</h1>
<div>{post.body}</div>
</article>
);
}
```
- Export either `metadata` or `generateMetadata` from a segment, not both.
## Loading and error states
- Add `loading.tsx` for segments that fetch data, and `error.tsx` (must start with `'use client'`) with a retry button wired to the recovery function the error component receives (see the `error.js` reference for your Next.js version).
## Route handlers
```ts
// app/api/posts/[id]/route.ts
import { NextResponse } from 'next/server';
import { getPost } from '@/lib/posts';
export async function GET(_request: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const post = await getPost(id);
if (!post) return NextResponse.json({ error: 'Not found' }, { status: 404 });
return NextResponse.json(post);
}
```
- Validate request bodies with a schema in POST/PUT handlers and check authentication.
## Dynamic routes
- Use `generateStaticParams` for dynamic segments whose values are known at build time.
## Caching
- `fetch` is not cached by default. State the caching strategy: `'use cache'` with `cacheLife`/`cacheTag` when Cache Components is enabled (Next.js 16), and `revalidatePath`/`revalidateTag` after mutations.
## SEO files
- Generate `app/sitemap.ts` and `app/robots.ts` with `MetadataRoute.Sitemap` / `MetadataRoute.Robots` types, set canonical URLs with `alternates.canonical`, and use one `<h1>` per page.
Add performance monitoring and analytics
Generate React forms with react-hook-form and Zod: shared schemas, labelled field components, accessible error messages, async validation, submission state and tests.
Generate strictly typed TypeScript: strict plus chosen extra checks, explicit return types on exported APIs, no any, derived types, sound guards, typed errors, small generic utilities and TSDoc.
Windsurf
framework
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A Windsurf user asks for a blog post page and matching API route in a Next.js 16 app; previous generations typed params synchronously and omitted metadata.
Generate app/blog/[slug]/page.tsx with metadata, app/api/posts/[id]/route.ts, loading and error files, and app/sitemap.ts.
Files that await params in the page, generateMetadata and the route handler; metadata with title, description, canonical and Open Graph; notFound() for missing posts; loading.tsx; a client error.tsx with retry; a typed GET handler returning 404 JSON; and a sitemap.ts typed with MetadataRoute.Sitemap.
Windsurf's rules documentation (docs.windsurf.com/windsurf/cascade/memories) now redirects to Devin documentation, which describes rules for the Devin Local agent in Devin Desktop. Current rules live in .devin/rules/*.md with a trigger setting, and the legacy Windsurf files (.windsurf/rules/*.md, .windsurf/global_rules.md and .windsurfrules) are still imported by default. AGENTS.md files are read as always-on rules.
.devin/rules/windsurf-next-js-page-generation.mdStarting point, not a tested configuration for your repository. Applied when files matching globs are involved (trigger: glob). Review the instructions, adapt the file paths and run your project's existing checks.
---
trigger: glob
globs: "**/*"
---
When generating Next.js App Router code (Next.js 15/16):
## Conventions
- Use the `app/` directory: `page.tsx`, `layout.tsx`, `loading.tsx`, `error.tsx`, `not-found.tsx`, and `route.ts` for API endpoints. Pages and layouts are Server Components by default.
- `params` and `searchParams` are Promises in pages, layouts, metadata functions and route handlers; await them.
## Metadata
```tsx
// app/blog/[slug]/page.tsx
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { getPost } from '@/lib/posts';
type Props = { params: Promise<{ slug: string }> };
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { slug } = await params;
const post = await getPost(slug);
if (!post) return {};
return {
title: post.title,
description: post.excerpt,
alternates: { canonical: `/blog/${slug}` },
openGraph: { title: post.title, description: post.excerpt, type: 'article' },
};
}
export default async function BlogPostPage({ params }: Props) {
const { slug } = await params;
const post = await getPost(slug);
if (!post) notFound();
return (
<article>
<h1>{post.title}</h1>
<div>{post.body}</div>
</article>
);
}
```
- Export either `metadata` or `generateMetadata` from a segment, not both.
## Loading and error states
- Add `loading.tsx` for segments that fetch data, and `error.tsx` (must start with `'use client'`) with a retry button wired to the recovery function the error component receives (see the `error.js` reference for your Next.js version).
## Route handlers
```ts
// app/api/posts/[id]/route.ts
import { NextResponse } from 'next/server';
import { getPost } from '@/lib/posts';
export async function GET(_request: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const post = await getPost(id);
if (!post) return NextResponse.json({ error: 'Not found' }, { status: 404 });
return NextResponse.json(post);
}
```
- Validate request bodies with a schema in POST/PUT handlers and check authentication.
## Dynamic routes
- Use `generateStaticParams` for dynamic segments whose values are known at build time.
## Caching
- `fetch` is not cached by default. State the caching strategy: `'use cache'` with `cacheLife`/`cacheTag` when Cache Components is enabled (Next.js 16), and `revalidatePath`/`revalidateTag` after mutations.
## SEO files
- Generate `app/sitemap.ts` and `app/robots.ts` with `MetadataRoute.Sitemap` / `MetadataRoute.Robots` types, set canonical URLs with `alternates.canonical`, and use one `<h1>` per page.
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
The docs recommend keeping rules short and specific. The current docs say AGENTS.md, AGENTS.local.md and AGENT.md are read as always-on rules, including files in subdirectories. Use .devin/rules/ when you need glob, model-decision or manual triggers.
Documentation checked 2026-11-05: Devin docs: Local customizations (redirect target of Windsurf memories docs)Windsurf docs: Cascade memories (redirects)
Add performance monitoring and analytics
Generate React forms with react-hook-form and Zod: shared schemas, labelled field components, accessible error messages, async validation, submission state and tests.
Generate strictly typed TypeScript: strict plus chosen extra checks, explicit return types on exported APIs, no any, derived types, sound guards, typed errors, small generic utilities and TSDoc.