-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
[Routing] Using redirect from server action always uses "replace" redirect type #53911
Comments
I can confirm this bug. @joshfullmer Could you point to the code where:
|
Getting this behaviour as well. Worked around it for now by having my server action, which is called from within an This will probably not cover all cases though. Server Action, heavily redacted "use server";
export async function runSearch(...) {
// [...]
if (result) {
// redirect(`/device/cubic/${result.id}`);
return {
redirect: true,
redirectUri: `/device/cubic/${result.id}`,
result: [],
error: null,
};
}
// [...]
} Form submit "use client";
<form
onSubmit={(e) => {
e.preventDefault();
setError(null);
startTransition(async () => {
try {
const result = await runSearch(query, activeCategory);
if (result?.redirect && result.redirectUri) {
return router.push(result.redirectUri);
}
if (result?.result) {
setResults(result?.result);
}
} catch (error) {
setError(error as { status: number; message: string });
}
});
}}
> |
Closes #53911. When calling `redirect()` instead a Server Action, the previous route should exist in the history when it's handled by the framework.
Thanks for the super fast PR #54458 and review @shuding @ijjk 🙌 This change was released in |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000 Binaries: Node: 16.15.1 npm: 8.11.0 Yarn: 1.22.19 pnpm: 8.6.11 Relevant Packages: next: 13.4.14-canary.2 eslint-config-next: 13.4.13 react: 18.2.0 react-dom: 18.2.0 typescript: 5.1.6 Next.js Config: output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
Routing (next/router, next/navigation, next/link)
Link to the code that reproduces this issue or a replay of the bug
https://github.com/joshfullmer/redirect-test
To Reproduce
Setup:
RedirectType.push
option.Steps:
Expected:
Actual:
Describe the Bug
When using the
redirect
function fromnext/navigation
in a server function, the redirect type is always "replace".The docs say that "push" is the default value for redirect type in the
redirect
function when used in server actions, but that does not appear to happen. The current route always appears to be replaced, even when the redirect type is explicitlyRedirectType.push
.Expected Behavior
When
redirect
is used within a server action, the default value for redirect type of "push" should be respected, and browser history should include the previous page.Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
NEXT-1551
The text was updated successfully, but these errors were encountered: