Sites Web10 min de lecture

Server Actions Next.js 15 : patterns production 2026

Mohamed Bah·Fondateur, Kolonell
26 mai 2026
Partager :
Server Actions Next.js 15 : patterns production 2026

Server Actions Next.js 15 : patterns production 2026

Sites Web

Next.js 14 a stabilisé Server Actions. Next.js 15 (release 2024) les a affinés. En 2026, ils remplacent ~70 % des API routes pour mutations form-driven. Mais patterns production = peu documentés. Voici les 8 patterns essentiels.

TL;DR

- Server Actions = fonctions serveur appelables directement depuis composants React.

- Avantages : type-safe, no API endpoint, progressive enhancement.

- Patterns : validation Zod, optimistic UI, revalidation, error handling.

Server Action basique

`tsx

// app/actions/posts.ts

'use server';

import { revalidatePath } from 'next/cache';

import { z } from 'zod';

import { prisma } from '@/lib/prisma';

const CreatePostSchema = z.object({

title: z.string().min(3).max(200),

content: z.string().min(10),

});

export async function createPost(formData: FormData) {

const parsed = CreatePostSchema.safeParse({

title: formData.get('title'),

content: formData.get('content'),

});

if (!parsed.success) {

return { error: parsed.error.flatten() };

}

const post = await prisma.post.create({ data: parsed.data });

revalidatePath('/posts');

return { success: true, post };

}

`

`tsx

// Usage dans component

import { createPost } from '@/app/actions/posts';

export function CreatePostForm() {

return (