Skip to content

Commit b8c84a5

Browse files
authored
🐞 fix (server): support for awaiting next.js 15 params (#1805)
1 parent fac631b commit b8c84a5

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

packages/server/src/next/app-route-handler.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import { AppRouteRequestHandlerOptions } from '.';
66
import { RPCApiHandler } from '../api';
77
import { loadAssets } from '../shared';
88

9-
type Context = { params: { path: string[] } };
9+
type Context = { params: Promise<{ path: string[] }> | { path: string[] } };
1010

1111
/**
1212
* Creates a Next.js 13 "app dir" API route request handler which encapsulates Prisma CRUD operations.
1313
*
14+
* @remarks Since Next.js 15, `context.params` is asynchronous and must be awaited.
1415
* @param options Options for initialization
1516
* @returns An API route request handler
1617
*/
@@ -27,18 +28,25 @@ export default function factory(
2728
return NextResponse.json({ message: 'unable to get prisma from request context' }, { status: 500 });
2829
}
2930

31+
let params: Context['params'];
3032
const url = new URL(req.url);
3133
const query = Object.fromEntries(url.searchParams);
3234

33-
if (!context.params.path) {
35+
try {
36+
params = await context.params;
37+
} catch {
38+
return NextResponse.json({ message: 'Failed to resolve request parameters' }, { status: 500 });
39+
}
40+
41+
if (!params.path) {
3442
return NextResponse.json(
3543
{ message: 'missing path parameter' },
3644
{
3745
status: 400,
3846
}
3947
);
4048
}
41-
const path = context.params.path.join('/');
49+
const path = params.path.join('/');
4250

4351
let requestBody: unknown;
4452
if (req.body) {

0 commit comments

Comments
 (0)