Skip to content

Next.js 15 requires params in Route Handlers to be awaited #1797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AmruthPillai opened this issue Oct 22, 2024 · 6 comments
Closed

Next.js 15 requires params in Route Handlers to be awaited #1797

AmruthPillai opened this issue Oct 22, 2024 · 6 comments

Comments

@AmruthPillai
Copy link
Contributor

AmruthPillai commented Oct 22, 2024

I'm using the latest @zenstackhq/server/next package, which exports the NextRequestHandler.

I get this error while running the server:

Error:  In route /api/model/[...path] a param property was accessed directly with `params.path`. `params` should be awaited before accessing its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`.

Probably NextRequestHandler should be updated to await the params props before being accessed. AFAIK, I couldn't find a way to await it myself.

@ymc9
Copy link
Member

ymc9 commented Oct 23, 2024

Thanks for bringing this up @AmruthPillai ! We should fix it soon. Would you be interested in making a PR for it? I'll be happy to facilitate.

@AmruthPillai
Copy link
Contributor Author

@ymc9 I have raised PR for the same, followed the contribution guide to match the right branch to fork from (dev). Hope it looks alright.

@ymc9
Copy link
Member

ymc9 commented Oct 25, 2024

Hi @AmruthPillai , thanks for making the PR!

I'm testing Next15 and I found the compiler complains about the typing of the API route handler:

Type error: Route "src/app/api/model/[...path]/route.ts" has an invalid "GET" export:
  Type "Context" is not a valid type for the function's second argument.
    Expected "Promise<any>", got "Promise<{ path: string[]; }> | { path: string[]; }".

Have you noticed the same thing in your environment? I don't know why Next wants us to use a weak typing ...

@ymc9
Copy link
Member

ymc9 commented Oct 25, 2024

Oh, I think it requires the type of the second parameter to be entirely a promise now. I'll make a change.

@ymc9
Copy link
Member

ymc9 commented Oct 25, 2024

Fixed in 2.7.4

@ymc9 ymc9 closed this as completed Oct 25, 2024
@AmruthPillai
Copy link
Contributor Author

@ymc9 Thank you for taking over. I was just wondering what would be the compatibility for users using Zenstack pre-Next.js 15, but as long as it works, that's perfect. Looking forward to seeing this in the release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants