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

redirect not working when open v3_singleFetch mode #10287

Open
licongy opened this issue Nov 30, 2024 · 1 comment
Open

redirect not working when open v3_singleFetch mode #10287

licongy opened this issue Nov 30, 2024 · 1 comment

Comments

@licongy
Copy link

licongy commented Nov 30, 2024

Reproduction

When v3_singleFetch mode is turned true, the return redirection in the action does not work.

not work:

export async function action({ request }: ActionFunctionArgs) {
  try {
    return data(null, { status: 302, headers: { "Location": "/" } })
  } catch {
    // pass
  }
}

not work:

    return redirect("/")

not work:

    return redirect("/", {
      status: 302,
      headers: {
        "Set-Cookie": await destroySession(session),    // this line will work, but it won't redirect in the browser
      },
    });

not work:

    return new Response(null, {
      status: 303,
      headers: {
        "Set-Cookie": await destroySession(session),   // this line will work, but it won't redirect in the browser
        Location: "/"   // this line will not work
      },
    });

the only way that STILL WORK:

    return json({ redirectTo: c.logoutRedirectPath }, {
      headers: {
        "Set-Cookie": await destroySession(session),
      },
    });

System Info

System:
    OS: macOS 15.1.1
    CPU: (8) arm64 Apple M1
    Memory: 101.67 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.10.0 - ~/.nvm/versions/node/v22.10.0/bin/node
    npm: 10.9.1 - ~/codespace/projects/sceneo-frontend/node_modules/.bin/npm
    pnpm: 9.14.2 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 131.0.6778.86
    Safari: 18.1.1
  npmPackages:
    @remix-run/dev: ^2.15.0 => 2.15.0 
    @remix-run/node: ^2.15.0 => 2.15.0 
    @remix-run/react: ^2.15.0 => 2.15.0 
    @remix-run/serve: ^2.15.0 => 2.15.0 
    vite: ^5.4.11 => 5.4.11

Used Package Manager

pnpm

Expected Behavior

In the action's return, the expected page jump to the specified url is performed.

Actual Behavior

In the action's return, it doesn't jump the page to the parameter-specified url as expected.

@gregleeper
Copy link

gregleeper commented Dec 4, 2024

This is how I'm doing my redirects in the action function with single fetch enabled.

import {
  redirect,
  type ActionFunctionArgs,
} from "@remix-run/node";

export async function action({ request, params }: ActionFunctionArgs) {
  const url = new URL(request.url);
  return redirect(new URL(`status`, url).toString());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants