vercel / next.js

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

next/link with absolute URL paths + wildcard subdomains broken after using browser back button #58649

Open aliceisjustplaying opened 9 months ago

aliceisjustplaying commented 9 months ago

Link to the code that reproduces this issue

https://github.com/aliceisjustplaying/broken-next-link-repro

To Reproduce

  1. Go to https://paperclip.monster
  2. Click on one of the links ("Page 1" or "Page 2")
  3. Click the browser back button
  4. Try clicking the same link as you clicked the first time
  5. Stare in disbelief that literally nothing happens.

This bug hinges on a few things:

  1. It only happens in prod (deployed to vercel), cannot repro on localhost AND
  2. With an apex domain (hence the need to test it at https://paperclip.monster or use another apex domain) AND
  3. Because we're using wildcard subdomains with a middleware AND
  4. I'm linking to the the two aforementioned through their absolute path, like this:
    import Link from "next/link";
    [...]
    <Link href="https://page1.paperclip.monster">Page 1</Link>
    <Link href="https://page2.paperclip.monster">Page 2</Link>

(Yes I know this may be considered bad practice. It should still work and it used to.)

Current vs. Expected behavior

Current: When I click a link, use the back button and click the same link again, nothing happens Expected: When I click a link, use the back button and click the same link again, it works

Verify canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.1.0: Mon Oct  9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000
Binaries:
  Node: 21.2.0
  npm: 10.2.4
  Yarn: 1.22.19
  pnpm: 8.10.5
Relevant Packages:
  next: 14.0.4-canary.4
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

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

App Router, Middleware / Edge (API routes, runtime), Routing (next/router, next/navigation, next/link)

Additional context

I've binary searched the canaries to find when this broke and it happened somewhere between v14.0.3-canary.5 and v14.0.3-canary.6 if I got it right. Looking at the commits, I think I did, though I don't know what exactly breaks this.

Chetax commented 9 months ago

@aliceisjustplaying ,sorry but i not get what problem you are getting can you please bit explain it and as you mention in expected behavior it works same as i see.

aliceisjustplaying commented 9 months ago

@Chetax here is a screen recording, Chrome in Guest mode which is as vanilla as it can get

https://github.com/vercel/next.js/assets/81575558/c408dae3-8af7-4bbc-b039-75bffb88ff3f

Chetax commented 9 months ago

Yes @aliceisjustplaying i understand. If Your Sign In With Your Account In Crome Then This Error Is Not Get Seen But When We Use incognito mode or Guest Mode Then This Error Get Occurs. Okay Let Us Figuring Out.

aliceisjustplaying commented 9 months ago

No, this error very much happens in my Chrome version when signed in as well.

Chetax commented 9 months ago

@aliceisjustplaying As I Login In Crome It Not Showing Me error But When I Use Incognito Mode It Does Show Error.

https://github.com/vercel/next.js/assets/99749401/55d07c30-cb11-4bf2-ab97-787857a26bbd

oscarsson444 commented 9 months ago

I have the same error on a website deployed on Netlify. A button navigates with a Link element (router.push has same behavior) to another page, I press back button then try to go to the same page again and nothing happens.

aliceisjustplaying commented 9 months ago

@oscarsson444 ah, good to know I'm not alone.

Leonardll commented 9 months ago

same here :)

Edit by maintainers: 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!

Diabl0570 commented 9 months ago

Iam facing the same issue, both with the useRouter as with <Link> component.

Interesting: For me it only works without incognito mode in chrome, if I enable it it does not work, for my colleague its the exact other way around!

ducofronik commented 9 months ago

We are facing the same issue. For me it is consistently failing in one Chrome profile and working in another Chrome profile (different account, same chrome extensions).

aliceisjustplaying commented 8 months ago

@Diabl0570 @ducofronik are you guys also using a middleware and wildcard domains?

Diabl0570 commented 8 months ago

@aliceisjustplaying, I do use middleware yes, but im not 100% sure what you main by wildcard domains? We do use wildcard in the middelware matcher, images remotePatterns and in the rewrites / redirects.

CarlosRubioRincon commented 8 months ago

I am experiencing the same behaviour when deploying to Vercel with NextJS 14.0.4.