More Next.js answers

by Danny
Published 2 min read

Since Next.js 15, params and searchParams are Promises, and Next.js 16 removed synchronous access. Learn how to await them in pages, layouts, routes and Client Components.

The short answer

#

In the App Router, params and searchParams are Promises. Make your page or layout async and await them before reading a property. In a Client Component, unwrap them with React's use, or read the URL with useParams and useSearchParams.


_10
-export default function Page({ params }: { params: { slug: string } }) {
_10
- const { slug } = params;
_10
+export default async function Page({ params }: { params: Promise<{ slug: string }> }) {
_10
+ const { slug } = await params;
_10
return <h1>{slug}</h1>;
_10
}

Why it happens

#

Next.js 15 changed params, searchParams, cookies(), headers() and draftMode() to be asynchronous. Making them Promises lets Next.js prepare as much of a page as possible before the request-specific values are known, which is the basis of streaming and partial prerendering.

To ease the change, Next.js 15 kept a temporary synchronous fallback and logged a warning in development when you read a property directly:


_10
Route "/blog/[slug]" used `params.slug`. `params` should be awaited before using its properties.

Next.js 16 removed that fallback, so synchronous access no longer works at all. Reading params.slug gives you a property of a Promise, which is undefined, and TypeScript reports an error if your types are correct.

This applies to params in page, layout, route, default and the metadata image files such as opengraph-image and icon, and to searchParams in page.

How to fix it

#

Await them in Server Components


_13
// app/blog/[slug]/page.tsx
_13
export default async function Page({
_13
params,
_13
searchParams,
_13
}: {
_13
params: Promise<{ slug: string }>;
_13
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
_13
}) {
_13
const { slug } = await params;
_13
const { tab } = await searchParams;
_13
_13
return <Post slug={slug} tab={typeof tab === 'string' ? tab : 'overview'} />;
_13
}

Do the same in generateMetadata, and in Route Handlers, where params comes from the second argument:


_10
// app/api/posts/[id]/route.ts
_10
export async function GET(
_10
request: Request,
_10
{ params }: { params: Promise<{ id: string }> }
_10
) {
_10
const { id } = await params;
_10
return Response.json(await getPost(id));
_10
}

Use the generated type helpers

Run npx next typegen to get globally available PageProps, LayoutProps and RouteContext types. They are typed from your actual route, so the param names are checked for you:


_10
export default async function Page(props: PageProps<'/blog/[slug]'>) {
_10
const { slug } = await props.params;
_10
return <h1>{slug}</h1>;
_10
}

Unwrap them in Client Components

Client Components cannot be async. If a page file is a Client Component, unwrap the Promise with use:


_10
'use client';
_10
_10
import { use } from 'react';
_10
_10
export default function Page({ params }: { params: Promise<{ slug: string }> }) {
_10
const { slug } = use(params);
_10
return <h1>{slug}</h1>;
_10
}

For components deeper in the tree, useParams and useSearchParams from next/navigation read the current URL without any prop passing.

Run the codemod

The async request APIs codemod converts most call sites for you, and adds a comment where it cannot:


_10
npx @next/codemod@canary next-async-request-api .

Search for @next-codemod-error comments and UnsafeUnwrapped casts afterwards and fix each one by hand.

Common pitfalls

#
  • Updating the code but not the types. If you still type params as a plain object, TypeScript will not warn you about missing await calls.
  • Awaiting only in the page and passing the raw Promise to a child that reads it synchronously.
  • Forgetting generateMetadata and generateStaticParams. generateMetadata receives Promise params; generateStaticParams returns plain objects and does not change.
  • Treating searchParams values as strings. Each value can be a string, an array of strings or undefined.
  • Making a Client Component async to use await. Use use instead.
#

Was this resource helpful?