Next.js 15 & React 19 - Những Thay Đổi Quan Trọng và Hướng Dẫn Migration
Server Components, Actions và Performance
Next.js 15 kết hợp với React 19 mang đến nhiều cải tiến đột phá: React Compiler, Server Actions ổn định, Partial Prerendering. Hướng dẫn chi tiết cách upgrade từ Next.js 14 và tận dụng các tính năng mới.
Next.js 15 + React 19: Những thay đổi bạn cần biết
Sau gần một năm phát triển, Next.js 15 đã chính thức ra mắt với nhiều tính năng đột phá. Kết hợp với React 19, đây là bản cập nhật lớn nhất kể từ App Router.
🆕 Điểm mới trong Next.js 15
1. React Compiler (Experimental)
Tự động memoize components và hooks, không cần useMemo, useCallback thủ công:
// Trước đây - cần memo thủ công
const MemoizedComponent = memo(function Component({ data }) {
const processed = useMemo(() => expensiveCalc(data), [data]);
return <div>{processed}</div>;
});2. Partial Prerendering (PPR)
Kết hợp static và dynamic rendering trong cùng một page:
// Static shell được serve ngay lập tức
// Dynamic parts được stream sau
export default async function ProductPage({ params }) {
return (
<div>
<StaticHeader />
<Suspense fallback={<Skeleton />}>
<DynamicProductDetails id={params.id} />
</Suspense>
</div>
);
}
3. Server Actions ổn định
Không còn experimental, sẵn sàng cho production:
// app/actions.ts
"use server"4. Caching mặc định thay đổi
Quan trọng: fetch requests không còn cache mặc định:
// Next.js 14: cached by default
// Next.js 15: no-store by default// Cần explicit cache
fetch(url, { cache: "force-cache" });
⚛️ React 19 Highlights
1. use() Hook
import { use } from "react";2. Actions trong Forms
function Form() {
async function handleSubmit(formData) {
"use server";
await saveData(formData);
}3. useOptimistic & useFormStatus
import { useOptimistic, useFormStatus } from "react";🔄 Hướng dẫn Migration từ Next.js 14
- Update dependencies:
npm install next@15 react@19 react-dom@19 - Chạy codemod:
npx @next/codemod@canary upgrade latest - Review caching strategy - thêm explicit cache nếu cần
- Test toàn bộ app, đặc biệt các async components
📊 Performance Benchmarks
| Metric | Next.js 14 | Next.js 15 | Improvement |
|---|---|---|---|
| Cold Start | 350ms | 280ms | 20% faster |
| Build Time | 45s | 38s | 15% faster |
| Bundle Size | 95KB | 82KB | 14% smaller |
🎯 Kết luận
Next.js 15 + React 19 là combo mạnh mẽ cho production apps. Với React Compiler và PPR, performance được cải thiện đáng kể mà không cần thay đổi nhiều code. Hãy bắt đầu migrate ngay hôm nay!
Bình luận (0)