79354490

Date: 2025-01-14 09:25:53
Score: 1.5
Natty:
Report link

I have the same problem in server action from RSC passing Next14 to Next15. But previously I fixed it on Next14 using try/finally :

Next documentation :

redirect internally throws an error so it should be called outside of try/catch blocks.

Next 13.4 Error: NEXT_REDIRECT in API routes:

export default async function Page() {
    let redirectPath: string | null = null

    try {
        //Rest of the code
        redirectPath = `/dashboard`
    } catch (error) {
        //Rest of the code
        redirectPath = `/`
    } finally {
        //Clear resources
        if (redirectPath)
            redirect(redirectPath)
    }

    return <>{/*Rest of JSX*/}</>
}

The only solution I can see is to return some typed error caught by all your server actions and pages to do the redirection on top level.

Reasons:
  • Blacklisted phrase (1): I have the same problem
  • Whitelisted phrase (-2): I fixed
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): I have the same problem
  • Low reputation (1):
Posted by: Chamchungue