Next.js Discord

Discord Forum

Redirect from server actions results in 404 until page refresh

Unanswered
southclaws posted this in #help-forum
Open in Discord
I'm building an extremely simple form flow for a client - essentially a typeform style flow. When you hit the submit button, a super simple server action fires and then redirects to the next page. But this always results in a 404 until refreshed. The URL is valid, because the refresh works but redirect() is definitely broken in some way here. There's nothing else going on, no error boundaries or calls to notFound() in the codebase. No idea how this could be happening on such a basic setup. No error messages either.

I'm using latest Canary so it looks like a new bug. Does not occur on latest stable.

10 Replies

Britannia Petite
show server action code pls and form code pls
it's behind NDA but I'll try to find time to write a minimal repro
but essentially, it's an extremely basic server component:

export async function Page() {
  const result = db.query(...)

  function f() {
    db.update(...)

    redirect(`/a/${some}/b/${params}/c/`)
  }

  return <form action={f}> ... </form>
}


the address bar in the browser reflects exactly what is expected, the URL is correect (confirmed by logging it out too) but the default Next.js 404 page appears and upon refreshing the page, the correct page loads (no changes to the URL)
No, the page exists already, there's zero calls to notFound in the entire codebase
It's essentially a form flow where each step of the form exists beforehand
so every permutation of the path already exists, that's why I was so puzzled it triggered the default 404 page
I've now seen it also on our login page, which also uses a server action and redirect("/some-static-page") once the user is logged in, so I'm suspecting it's specific to server actions - will experiment some more
it's not happening on stable though, only canary, so at least we can still continue working