Next.js 15 & React 19 Optimizer Skill
This skill provides expertise in optimizing applications using the latest Next.js 15 features and React 19 improvements.
Key Focus Areas
- •React Compiler (React Forget): Leverage automatic memoization. Learn when to rely on the compiler and when manual
useMemo/useCallbackmight still be needed for complex dependencies. - •Turbopack Integration: Efficiently use the new Rust-based bundler for faster development and builds.
- •Async Request APIs: Properly handle the shift to asynchronous APIs for
cookies(),headers(), andparamsin the App Router. - •Partial Prerendering (PPR): Implement hybrid rendering by combining static shell components with dynamic islands for optimal LCP and user experience.
- •Enhanced Caching: Configure Next.js 15 caching strategies, specifically the new default behaviors for fetch requests and segment configs.
Best Practices Checklist
- • React 19 Hooks: Use new hooks like
useActionStateanduseFormStatusfor streamlined form handling. - • Server Actions: Ensure Server Actions are secure and follow the "Client-side validation, Server-side verification" pattern.
- • Async Params: Access
paramsandsearchParamsas Promises in Page/Layout components. - • Hydration Error Debugging: Utilize the improved hydration error messages in Next.js 15 to quickly identify and fix mismatches.
- •
<Form>Component: Use the built-in<Form>component for progressive enhancement and better prefetching.
Code Snippets
Async Params in Next.js 15
tsx
// Page.tsx
export default async function Page({
params,
}: {
params: Promise<{ slug: string }>;
}) {
const { slug } = await params;
return <div>Post: {slug}</div>;
}
Partial Prerendering (PPR)
tsx
// layout.tsx
export const experimental_ppr = true; // Enable PPR for the segment
export default function Layout({ children }) {
return (
<div>
<Header /> {/* Static shell */}
<Suspense fallback={<Skeleton />}>
{children} {/* Dynamic content */}
</Suspense>
</div>
);
}
Troubleshooting
- •"Property 'params' does not exist": Parameters are now Promises. Ensure you
awaitthem or useReact.use()in Client Components. - •Hydration Mismatch: Next.js 15 provides better diffs; look for "Expected ... but found ..." in the console.
- •Turbopack Issues: If certain plugins aren't working, check the documentation for Turbopack-specific configuration options.