To update to Next.js version 15, you can use the upgrade codemod:
Terminal
npx @next/codemod@canary upgrade latest
If you prefer to do it manually, ensure that you're installing the latest Next & React versions:
Terminal
npm i next@latest react@latest react-dom@latest eslint-config-next@latest
Good to know
If you see a peer dependencies warning, you may need to update react and react-dom to the suggested versions, or use the --force or --legacy-peer-deps flag to ignore the warning. This won't be necessary once both Next.js 15 and React 19 are stable.
The minimum versions of react and react-dom is now 19.
useFormState has been replaced by useActionState. The useFormState hook is still available in React 19, but it is deprecated and will be removed in a future release. useActionState is recommended and includes additional properties like reading the pending state directly. Learn more.
useFormStatus now includes additional keys like data, method, and action. If you are not using React 19, only the pending key is available. Learn more.
import { cookies, type UnsafeUnwrappedCookies } from 'next/headers'// Beforeconst cookieStore = cookies()const token = cookieStore.get('token')// Afterconst cookieStore = cookies() as unknown as UnsafeUnwrappedCookies// will log a warning in devconst token = cookieStore.get('token')
import { headers, type UnsafeUnwrappedHeaders } from 'next/headers'// Beforeconst headersList = headers()const userAgent = headersList.get('user-agent')// Afterconst headersList = headers() as unknown as UnsafeUnwrappedHeaders// will log a warning in devconst userAgent = headersList.get('user-agent')
import { draftMode, type UnsafeUnwrappedDraftMode } from 'next/headers'// Beforeconst { isEnabled } = draftMode()// After// will log a warning in devconst { isEnabled } = draftMode() as unknown as UnsafeUnwrappedDraftMode
The runtimesegment configuration previously supported a value of experimental-edge in addition to edge. Both configurations refer to the same thing, and to simplify the options, we will now error if experimental-edge is used. To fix this, update your runtime configuration to edge. A codemod is available to automatically do this.
To opt specific fetch requests into caching, you can pass the cache: 'force-cache' option.
app/layout.js
export default async function RootLayout() { const a = await fetch('https://...') // Not Cached const b = await fetch('https://...', { cache: 'force-cache' }) // Cached // ...}
To opt all fetch requests in a layout or page into caching, you can use the export const fetchCache = 'default-cache'segment config option. If individual fetch requests specify a cache option, that will be used instead.
app/layout.js
// Since this is the root layout, all fetch requests in the app// that don't set their own cache option will be cached.export const fetchCache = 'default-cache'export default async function RootLayout() { const a = await fetch('https://...') // Cached const b = await fetch('https://...', { cache: 'no-store' }) // Not cached // ...}
GET functions in Route Handlers are no longer cached by default. To opt GET methods into caching, you can use a route config option such as export const dynamic = 'force-static' in your Route Handler file.
app/api/route.js
export const dynamic = 'force-static'export async function GET() {}
When navigating between pages via <Link> or useRouter, page segments are no longer reused from the client-side router cache. However, they are still reused during browser backward and forward navigation and for shared layouts.
To opt page segments into caching, you can use the staleTimes config option:
The geo and ip properties on NextRequest have been removed as these values are provided by your hosting provider. A codemod is available to automate this migration.
If you are using Vercel, you can alternatively use the geolocation and ipAddress functions from @vercel/functions instead:
middleware.ts
import { geolocation } from '@vercel/functions'import type { NextRequest } from 'next/server'export function middleware(request: NextRequest) { const { city } = geolocation(request) // ...}
middleware.ts
import { ipAddress } from '@vercel/functions'import type { NextRequest } from 'next/server'export function middleware(request: NextRequest) { const ip = ipAddress(request) // ...}