next.js: [NEXT-1167] Server Actions 405 "Method Not Allowed" when using generateStaticParams

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP PREEMPT_DYNAMIC Wed, 26 Apr 2023 20:50:14 +0000
    Binaries:
      Node: 18.16.0
      npm: 9.5.1
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.4.1
      eslint-config-next: 13.0.6-canary.1
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

No response Server actions. It seems like server actions wasn’t part of the issue form dropdown earlier

Link to the code that reproduces this issue

https://github.com/arduano/server-actions-repro

To Reproduce

  • npm install
  • npm run dev
  • Open /asdf in the browser
  • Click the button, observe the network requests in the browser’s dev tools

Describe the Bug

Including generateStaticParams in a page breaks server actions, making it return 405 on each request

Expected Behavior

The server actions behave as expected

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-1167

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 51
  • Comments: 30 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Trying to do internationalization, and in my end the same problem.

I am using generateStaticParams in the root layout, then server actions in all my routes get 405 method not allowed.

Removing generateStaticParams make it works, but it is not a fix as i need this for locales.

This is related to : https://github.com/vercel/next.js/issues/49373#issuecomment-1592656952

This error occurs in development only. Try building the app then running it in production, it will work just fine.

Error happens in production too, just not printing anything in server console (browser console and network tab still show 405)

This error occurs in development only. Try building the app then running it in production, it will work just fine.

Hi, can confirm just had the same bug. The moment I remove generateStaticParams from the page the action works.

Also, I have the same issue. I am removing the generateStaticParams function, and the server action works property. Why can’t we use both generateStaticParams and server actions?

405 error in production on [POST] from Vercel logs. Page renders static content correctly then errors on Server action POST…

We are talking about it in the next-intl repo as well: https://github.com/amannn/next-intl/discussions/353

I think next.js should look into this if they plan to release server actions as beta or stable soon

Didn’t find this issue at first because it doesn’t include the error message I am getting. In case anyone else gets the same error message, here it is:

Warning: Detected multiple renderers concurrently rendering the same context provider. This is currently unsupported.
    at PathnameContextProviderAdapter (/reproduction-app/node_modules/.pnpm/next@13.4.20-canary.23_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/shared/lib/router/adapters.shared-runtime.js:84:11)
    at Be (/reproduction-app/node_modules/.pnpm/next@13.4.20-canary.23_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/next-server/pages.runtime.dev.js:1:47861)
    at Ze (/reproduction-app/node_modules/.pnpm/next@13.4.20-canary.23_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/next-server/pages.runtime.dev.js:1:48550)
    at div
    at Ye (/reproduction-app/node_modules/.pnpm/next@13.4.20-canary.23_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/next-server/pages.runtime.dev.js:1:55624)

Bump

Is there anybody from Next on this issue? Happy to look into into it.

I found a workaround

You can currently bypass the error by turning your page from mypath/page.tsx to mypath/[[...slug]].tsx. This optional catch-all segment makes “/mypath” still accessible and magically works, by telling Next.js: This page must be dynamic. Inside of the route’s page.tsx, you can then make sure that only “/mypath” is matched by using notFound:

// mypath/[[...slug]].tsx
export default function Page({ params: { slug } }) {
  if (slug?.[0]) { notFound() }
  
  return <form action={myServerAction}> <button type="submit">Works like a charm</button> </form>

}

Made a YT video as well: https://youtu.be/K6Jn24FsZFc