5 min read
October 26 2024
This continuation highlights the key updates and enhancements introduced in Next.j
s 15, aimed at improving development workflows, boosting performance, and addressing important changes. With features like automated upgrades using the new codemod CLI, significant Turbopack optimizations, and enhanced security for Server Actions, Next.js 15 offers a wide range of tools to streamline processes. Here’s a closer look at the most important features and updates.uced in Next.j
You can access the first part of the overview on Next.js 15 by following this LINK 🧑💻
Codemods (automated code transformations) are included with every major Next.js release to help streamline the upgrade process for breaking changes. The new enhanced codemod CLI further simplifies upgrades. To upgrade to the latest stable or prerelease versions, use the following command:
npx @next/codemod@canary upgrade rc
This tool updates your dependencies, shows available codemods, and guides you through applying them. The specified dist tag on the command line (e.g.,
determines the version for the upgrade. @rc
, @canary
)
Turbopack for local development will reach stability with the general release of Next.js 15
, remaining as an opt-in feature. It can be tested today with the command:
next dev — turbo
Through community testing and internal efforts, 54 GitHub issues have been resolved since the first Next.js 15 Release Candidate. Recent optimization efforts have focused on cold compilation performance, resulting in:
Further improvements are in progress, including persistent caching, memory usage reduction, and Turbopack for the next build command, with 96% of tests currently passing.
To prepare for future optimizations, APIs that rely on request-specific data, such as headers, cookies, params, and searchParams, are being transitioned to asynchronous functions. An example of the new syntax is:
import { cookies } from 'next/headers';
export async function AdminPanel() {
const cookieStore = await cookies();
const token = cookieStore.get('token');
}
This change affects APIs like cookies
, headers
, draftMode
, and params
in layout.js
, page.js
, and more. While these APIs can still be accessed synchronously with warnings, upgrading is recommended.
To assist with the migration, run the following codemod:
npx @next/codemod@canary next-async-request-api .
For further details, consult the upgrade guide.
Server Actions are server-side functions callable from the client. Even if these functions are not imported, they remain publicly accessible HTTP endpoints, which can lead to unintentional exposure. To address this, several security enhancements have been introduced:
'use server';
export async function updateUserAction(formData) {}
export async function deleteUserAction(formData) {}
During development, Next.js now displays a Static Route Indicator to highlight whether routes are static or dynamic, helping with performance optimization. This indicator provides visual cues on how pages are rendered.
Rendering strategies for all routes can also be viewed in the
output. next build
The new <Form>
component extends the standard HTML <form>
element, offering prefetching, client-side navigation, and progressive enhancement. It's especially useful for forms that navigate to new pages, such as search forms.
During development, Next.js now displays a Static Route Indicator to highlight whether routes are static or dynamic, helping with performance optimization. This indicator provides visual cues on how pages are rendered.
Rendering strategies for all routes can also be viewed in the
output. next build
The new <Form>
component extends the standard HTML <form>
element, offering prefetching, client-side navigation, and progressive enhancement. It's especially useful for forms that navigate to new pages, such as search forms.
import Form from 'next/form';
export default function Page() {
return (
<Form action="/search">
<input name="query" />
<button type="submit">Submit</button>
</Form>
);
}
Features include:
Next.js now supports TypeScript configuration files (
, providing type safety and autocomplete with the next.config.ts
)NextConfig
type.
import type { NextConfig } from 'next';
const nextConfig: NextConfig = {
// config options
};
export default nextConfig;
instrumentation.js (Stable)
The instrumentation.js file and its register() API have reached stability. This feature enables monitoring performance, tracking errors, and integrating with observability libraries such as OpenTelemetry.
Additionally, the onRequestError hook allows capturing context around server errors and reporting them to an observability provider.
export async function onRequestError(err, request, context) {
await fetch('https://...', {
method: 'POST',
body: JSON.stringify({ message: err.message, request, context }),
headers: { 'Content-Type': 'application/json' },
});
}
export async function register() {
// Initialize your observability provider SDK
}
Server Components HMR
To enhance development performance, Hot Module Replacement (HMR) for Server Components has been improved. Now, HMR can reuse fetch responses from previous renders, reducing API call overhead during development.
Faster Static Generation
Static generation has been optimized, reducing build times by reusing the initial render to generate both client-side navigation data and HTML. Additionally, static generation workers now share the fetch cache across pages, minimizing redundant requests.
Advanced Static Generation Control
Experimental options for more control over static generation are now available. These options include controlling retry counts, worker concurrency, and page processing thresholds. It’s recommended to use these only for specific advanced use cases, as they can increase resource usage and lead to potential out-of-memory errors.
const nextConfig = {
experimental: {
staticGenerationRetryCount: 1,
staticGenerationMaxConcurrency: 8,
staticGenerationMinPagesPerWorker: 25
},
};
export default nextConfig;
When self-hosting applications, more control is now available over Cache-Control directives, especially for ISR pages. Two key improvements have been made:
In addition, image optimization has been streamlined. Manual installation of sharp is no longer required — Next.js automatically uses it when running in standalone mode.
With the end of life for ESLint 8 on October 5, 2024, Next.js adds support for ESLint 9 while maintaining backward compatibility. If your project hasn’t adopted the new ESLint config format, Next.js will automatically apply the
escape hatch to facilitate the transition. Deprecated options like ESLINT_USE_FLAT_CONFIG=false
and --ext
--ignore-path
are removed from
, anticipating further changes in ESLint 10. next lint
Next.js 15 continues to enhance developer experience with new features like the <Form>
component, TypeScript support for next.config.ts
, and the stable release of instrumentation.js. Additionally, various improvements have been made to self-hosting, image optimization, and static page generation.
These updates aim to streamline development, enhance performance, and ensure future compatibility with evolving JavaScript and Node.js ecosystems. Developers are encouraged to review the breaking changes and take advantage of the migration tools provided to ensure a smooth transition to Next.js 15.