vercel / next.js

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

Bugs with heuristic to "detect file by whether it has a dot" with trailingSlash #56090

Open taoky opened 1 year ago

taoky commented 1 year ago

Link to the code that reproduces this issue

https://github.com/taoky-playground/nextjs-remove-trailing-with-dot-bug

To Reproduce

  1. next export yarn build
  2. In exported index.html:
    <div><a href="/a/">a/</a><br/><a href="/b.git">b.git/</a></div>

    While:

    > ls out/
    404/  404.html  _next/  a/  b.git/  favicon.ico  index.html

Current vs. Expected behavior

Current: <a href="/b.git">b.git/</a>

Expected: <a href="/b.git/">b.git/</a>

Verify canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Wed, 13 Sep 2023 08:37:40 +0000
Binaries:
  Node: 18.13.0
  npm: 8.19.3
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 13.5.4-canary.1
  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)

Routing (next/router, next/navigation, next/link)

Additional context

Related (they are all locked):

It is fundamentally broken to "detect file" by checking whether it has a . or not -- this is not a Windows-only world, after all. Although most HTTP server could help redirect to the URL with a trailing slash:

Thus I believe that https://github.com/vercel/next.js/blob/3eadfe925bb49e116f1b97d81a1d51fa0e33166d/packages/next/src/client/normalize-trailing-slash.ts#L15 shall be removed (who will intentionally put a trailing slash after a file?).

SukkaW commented 1 year ago

Hello, the designer/builder of the https://mirrors.help here.

We found out about the issue when we were building the sie. You can also reproduce the error on our site:

taoky commented 1 year ago

I have worked out a demo to show this bug:

It also shows that this bug affects router.push(). Source code is at the gh-demo branch: https://github.com/taoky-playground/nextjs-remove-trailing-with-dot-bug/tree/gh-demo

Reproduction:

taoky commented 1 year ago

Possible related issue at Cloudflare side: https://github.com/cloudflare/workers-sdk/issues/2779