vercel / next.js

The React Framework
https://nextjs.org
MIT License
127k stars 26.99k forks source link

permanentRedirect doesn't send 308 status code with loading.js/tsx #59464

Open sam-hsbu opened 11 months ago

sam-hsbu commented 11 months ago

Link to the code that reproduces this issue

https://github.com/sam-hsbu/redirectPermanent

To Reproduce

  1. Create a folder in app. Let's call it "redirect".
  2. Create a page.tsx/js in this redirect folder.
  3. Content of this page should contains the permanentRedirect function :
import { permanentRedirect } from "next/navigation";

const page = () => {
  permanentRedirect("/");
};

export default page;

Now when we go to : http://localhost:3000/redirect, we are redirected to the homepage as expected, with a 308 status code :

Let's launch a curl.exe -X HEAD -I http://localhost:3000/redirect

We get this result as expected :

HTTP/1.1 308 Permanent Redirect Vary: RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url, Accept-Encoding Location: / Cache-Control: no-store, must-revalidate X-Powered-By: Next.js Content-Type: text/html; charset=utf-8 Connection: keep-alive Keep-Alive: timeout=5

  1. The issue appears when we have a "loading.js/tsx" file in the "app" folder, as simple as this :
export default function Loading() {
  return (
    <div>Wait !</div>
  );
}

The redirection is still made but the status code is 200 :

HTTP/1.1 200 OK Vary: RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url, Accept-Encoding Cache-Control: no-store, must-revalidate X-Powered-By: Next.js Content-Type: text/html; charset=utf-8 Connection: keep-alive Keep-Alive: timeout=5

  1. Remove the loading file and the 308 status code came back.

Current vs. Expected behavior

I expected a 308 status code with or without the loading page.

Verify canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home
Binaries:
  Node: 20.9.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.0.5-canary.5 (tried with next@latest too)
  eslint-config-next: 14.0.4
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router

Additional context

I tried with nextjs 14.0.1 , 14.0.4 and 14.0.5-canary.5.

maiconcarraro commented 11 months ago

I'm facing a similar issue, if I have the loading file, the redirect (not using permanent) doesn't happen immediately, it does a 200 first flickering the base layout, and then switch to the redirected page. If I remove the loading, it renders correctly all conditions.

sam-hsbu commented 11 months ago

Oh I'm not alone so :)

sam-hsbu commented 9 months ago

Is there anyone here ?

Please.

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

zipme commented 8 months ago

facing the same issue

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!