- Home
- Skills
- Frontend & Web Apps
- Next.js App Router Pro: Server-First, Cached Right
Next.js App Router Pro: Server-First, Cached Right
by Ignasi
Professional Next.js App Router engineering focusing on server-first components, caching, and secure Server Actions.
Free
Next.js App Router Pro: Server-First, Cached Right
Example session with this skill installed
Fix this post editor. It's currently a client component fetching data in a useEffect. Convert it to a server-first pattern with a Server Action for saving.
- Read your context and instructions
- Compiled the next js app
- Generated the UI component
I have refactored the post editor to follow Next.js App Router best practices. The data fetching is now handled by a Server Component, and the form submission uses a secure Server Action with Zod validation and optimistic updates.
Refactored Post Editor
app/posts/[id]/page.tsx (Server Component)
import { getPost } from "@/lib/db";
import { PostForm } from "./post-form";
import { notFound } from "next/navigation";
export default async function PostPage({ params }: { params: { id: string } }) {
const post = await getPost(params.id);
if (!post) notFound();
return (
<main>
<h1>Edit Post</h1>
<PostForm post={post} />
</main>
);
}
app/posts/[id]/actions.ts (Server Action)
"use server";
import { revalidatePath } from "next/cache";
import { z } from "zod";
import { updatePost } from "@/lib/db";
const schema = z.object({
id: z.string(),
title: z.string().min(3),
content: z.string(),
});
export async function savePost(prevState: any, formData: FormData) {
const validated = schema.safeParse({
id: formData.get("id"),
title: formData.get("title"),
content: formData.get("content"),
});
if (!validated.success) {
return { ok: false, fieldErrors: validated.error.flatten().fieldErrors };
}
await updatePost(validated.data);
revalidatePath(`/posts/${validated.data.id}`);
return { ok: true, error: null };
}
Next steps
- Verify the
updatePostdatabase function has proper authorization checks. - Add a
loading.tsxfile in the[id]directory to handle the transition state. - Test the form with empty values to trigger the Zod validation error messages.
page.tsx
TSX · React component
Example file from a real run - the skill writes it into your workspace.
Connects securely to your tools. The creator never sees your data.
About this skill
Next.js applications often suffer from "use client" overuse, hydration mismatches, and broken caching logic. This skill enforces a server-first architecture to ensure your App Router implementation is fast, type-safe, and SEO-optimized.
What it does
- Component architecting defines strict boundaries between Server and Client Components to minimize bundle size.
- Data fetching optimization implements parallel fetching, deduplication with
cache(), and version-specific caching strategies. - Mutation handling scaffolds Server Actions with Zod validation, auth checks, and revalidation logic.
- UX pattern implementation sets up streaming with Suspense,
loading.tsxsegments, and error boundaries. - Performance auditing manages
next/imageconfigurations, font optimization, and metadata generation.
How it works
- Environment detection by analyzing
package.json, Next.js version, and current directory structure. - Boundary definition where interactive logic is pushed to leaf components while data remains on the server.
- Fetching implementation using
Promise.allfor parallel requests and explicit cache tags for granular revalidation. - Validation and Action setup creating secure public endpoints with typed responses for form states.
- Verification via build checks to ensure routes are correctly categorized as static or dynamic.
Frameworks & tools
Optimized for Next.js 14, 15, and 16. Supports React, TypeScript, Zod, Prisma, Drizzle, Tailwind CSS, and standard auth libraries.
Why this beats prompting it yourself
Generic prompts often default to legacy Pages Router patterns or pollute the client bundle with server logic. This skill enforces server-only imports and ensures props crossing the boundary are serializable, preventing runtime hydration errors and security leaks.
Use cases
- Migrating a legacy React or Next.js Pages Router app to the modern App Router.
- Fixing "stale data" bugs by implementing correct
revalidateTagandrevalidatePathpatterns. - Debugging hydration mismatches and "NEXT_PUBLIC" environment variable leaks.
- Reducing Time to First Byte (TTFB) through Suspense-based streaming.
Known limitations
Does not support legacy Pages Router specific features like getServerSideProps. Requires TypeScript for full validation benefits.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
1 use
Times used to date
Free to use
No account required to browse
Trust & safety
Security scan
Security scan passed 11 days ago
- Free with an Agensi account
Permissions
What's inside
Frequently Asked Questions
New in Frontend & Web Apps
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Frontend & Web Apps.