Skip to content
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

Use push for Server Action redirections #54458

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ export function serverActionReducer(
action.mutable.inFlightServerAction!
) as Awaited<FetchServerActionResult>

// Make sure the redirection is a push instead of a replace.
// Issue: https://github.com/vercel/next.js/issues/53911
if (redirectLocation) {
state.pushRef.pendingPush = true
mutable.pendingPush = true
}

mutable.previousTree = state.tree

if (!flightData) {
Expand Down
18 changes: 18 additions & 0 deletions test/e2e/app-dir/actions/app-action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ createNextDescribe(
}, 'same')
})

it('should push new route when redirecting', async () => {
const browser = await next.browser('/header')

await browser.elementByCss('#setCookieAndRedirect').click()
await check(async () => {
return (await browser.elementByCss('#redirected').text()) || ''
}, 'redirected')

// Ensure we can navigate back
await browser.back()

await check(async () => {
return (
(await browser.elementByCss('#setCookieAndRedirect').text()) || ''
)
}, 'setCookieAndRedirect')
})

it('should support headers in client imported actions', async () => {
const logs: string[] = []
next.on('stdout', (log) => {
Expand Down
1 change: 1 addition & 0 deletions test/e2e/app-dir/actions/app/header/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default function UI({
</button>
<form>
<button
id="setCookieAndRedirect"
formAction={async () => {
await setCookieAndRedirect(
'redirect',
Expand Down