-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: server action redirects between multiple root layouts (#73063)
When handling a redirect through a server action, we pass in the current href rather than the destination href to `handleExternalUrl`, which is incorrect since that won't reflect the updated URL from a server action's redirect response. While looking into this, I noticed a handful of server action branches that weren't properly rejecting or resolving the action promises. This would cause the transitions to stall until they were fulfilled, so I updated all of the existing branches where we early return to also resolve the promise. Fixes #72842
- Loading branch information
Showing
4 changed files
with
53 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use server' | ||
|
||
import { redirect } from 'next/navigation' | ||
|
||
export async function redirectAction() { | ||
redirect('/result') | ||
} |
19 changes: 15 additions & 4 deletions
19
test/e2e/app-dir/root-layout/app/(multiple-root)/(root-a)/root-layout-a/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
import React from 'react' | ||
import Link from 'next/link' | ||
import { redirect } from 'next/navigation' | ||
|
||
export default async function Page() { | ||
async function redirectAction() { | ||
'use server' | ||
redirect('/root-layout-b') | ||
} | ||
|
||
export default function Page() { | ||
return ( | ||
<Link href="../root-layout-b" id="link-to-b"> | ||
To b | ||
</Link> | ||
<> | ||
<Link href="../root-layout-b" id="link-to-b"> | ||
To b | ||
</Link> | ||
<form action={redirectAction}> | ||
<button id="action-redirect-to-b">Redirect to B</button> | ||
</form> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters